diff options
author | Kenneth Graunke <[email protected]> | 2019-02-15 14:52:20 -0800 |
---|---|---|
committer | Dylan Baker <[email protected]> | 2019-02-19 07:07:04 -0800 |
commit | 69ebf4569ae0d2c7d9b1dc04de145329a1684727 (patch) | |
tree | 7fd8f5979078c6afef2278bd425c6a6ef51fce92 | |
parent | 385b7362385b4f648508768c20b057eed2022409 (diff) |
nir: Don't reassociate add/mul chains containing only constants
The idea here is to reassociate a * (b * c) into (a * c) * b, when
b is a non-constant value, but a and c are constants, allowing them
to be combined.
But nothing was enforcing that 'b' must be non-constant, which meant
that running opt_algebraic in a loop would never terminate if the IR
contained non-folded constant expressions like 256 * 0.5 * 2. Normally,
we call constant folding in such a loop too, but IMO it's better for
nir_opt_algebraic to be robust and not rely on that.
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109581
Fixes: 32e266a9a58 i965: Compile fp64 funcs only if we do not have 64-bit hardware support
Reviewed-by: Ian Romanick <[email protected]>
(cherry picked from commit 535251487ba56c4fd98465c4682881c2b9734242)
-rw-r--r-- | src/compiler/nir/nir_opt_algebraic.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 75a3d2ad238..636f3672708 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -618,11 +618,11 @@ optimizations = [ # Reassociate constants in add/mul chains so they can be folded together. # For now, we mostly only handle cases where the constants are separated by # a single non-constant. We could do better eventually. - (('~fmul', '#a', ('fmul', b, '#c')), ('fmul', ('fmul', a, c), b)), - (('imul', '#a', ('imul', b, '#c')), ('imul', ('imul', a, c), b)), - (('~fadd', '#a', ('fadd', b, '#c')), ('fadd', ('fadd', a, c), b)), - (('~fadd', '#a', ('fneg', ('fadd', b, '#c'))), ('fadd', ('fadd', a, ('fneg', c)), ('fneg', b))), - (('iadd', '#a', ('iadd', b, '#c')), ('iadd', ('iadd', a, c), b)), + (('~fmul', '#a', ('fmul', 'b(is_not_const)', '#c')), ('fmul', ('fmul', a, c), b)), + (('imul', '#a', ('imul', 'b(is_not_const)', '#c')), ('imul', ('imul', a, c), b)), + (('~fadd', '#a', ('fadd', 'b(is_not_const)', '#c')), ('fadd', ('fadd', a, c), b)), + (('~fadd', '#a', ('fneg', ('fadd', 'b(is_not_const)', '#c'))), ('fadd', ('fadd', a, ('fneg', c)), ('fneg', b))), + (('iadd', '#a', ('iadd', 'b(is_not_const)', '#c')), ('iadd', ('iadd', a, c), b)), # By definition... (('bcsel', ('ige', ('find_lsb', a), 0), ('find_lsb', a), -1), ('find_lsb', a)), |