Skip to content
  • Caio Oliveira's avatar
    nir: Fix nir_opt_idiv_const when negatives are involved · 6cb7779e
    Caio Oliveira authored and Juan A. Suárez's avatar Juan A. Suárez committed
    First, allow the case for negative powers of two.  Then ensure that we
    use the absolute value of the non-constant value to calculate the
    quotient -- this was hinted in the code by the name 'uq'.
    
    This fixes an issue when 'd' is positive and 'n' is negative.  The
    ishr will propagate the negative sign and we'll use nir_ineg() again,
    incorrectly.
    
    v2: First version used only ishr, but that isn't sufficient, since it
        never can produce a zero as a result.  (Jason)
        Allow negative powers of two.  (Caio)
    
    Fixes: 74492eba
    
     "nir: Add a pass for lowering integer division by constants"
    Reviewed-by: default avatarJason Ekstrand <jason@jlekstrand.net>
    (cherry picked from commit 8a995f2b)
    6cb7779e