nir: Fix nir_opt_idiv_const when negatives are involved
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Sat, 11 May 2019 07:15:41 +0000 (00:15 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Thu, 16 May 2019 17:55:03 +0000 (10:55 -0700)
commit8a995f2b5e1e3f2a2eafd32870ebfb43b5cfdf27
treeabeb63ad76b1f0fd22d1c0e2854b4690fc85b87c
parentef88e23d0335c05ebc60a621ee91cd6b22208597
nir: Fix nir_opt_idiv_const when negatives are involved

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: 74492ebad94 "nir: Add a pass for lowering integer division by constants"
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opt_idiv_const.c