From 00914e2179915a302a1c9f63b9a96ca0710b4132 Mon Sep 17 00:00:00 2001 From: Italo Nicola Date: Fri, 4 Sep 2020 18:26:01 +0000 Subject: [PATCH] nir/algebraic: fold some nested comparisons with ball and bany Signed-off-by: Italo Nicola Reviewed-by: Eric Anholt Reviewed-by: Boris Brezillon Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index c948faf74e1..f2ef598c912 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1820,6 +1820,16 @@ def bitfield_reverse(u): optimizations += [(bitfield_reverse('x@32'), ('bitfield_reverse', 'x'), '!options->lower_bitfield_reverse')] +# "all_equal(eq(a, b), vec(~0))" is the same as "all_equal(a, b)" +# "any_nequal(neq(a, b), vec(0))" is the same as "any_nequal(a, b)" +for ncomp in [2, 3, 4, 8, 16]: + optimizations += [ + (('ball_iequal' + str(ncomp), ('ieq', a, b), ~0), ('ball_iequal' + str(ncomp), a, b)), + (('ball_iequal' + str(ncomp), ('feq', a, b), ~0), ('ball_fequal' + str(ncomp), a, b)), + (('bany_inequal' + str(ncomp), ('ine', a, b), 0), ('bany_inequal' + str(ncomp), a, b)), + (('bany_inequal' + str(ncomp), ('fneu', a, b), 0), ('bany_fnequal' + str(ncomp), a, b)), + ] + # For any float comparison operation, "cmp", if you have "a == a && a cmp b" # then the "a == a" is redundant because it's equivalent to "a is not NaN" # and, if a is a NaN then the second comparison will fail anyway.