]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match: Fix `(a == b) | ((a|b) != 0)` pattern for vectors [PR122296]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 16 Oct 2025 23:10:59 +0000 (16:10 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 17 Oct 2025 05:00:45 +0000 (22:00 -0700)
The pattern `(a == b) | ((a|b) != 0)` uses build_one_cst to build boolean true
but boolean can be a signed multi-bit type. So this changes the result to
use constant_boolean_node isntead.
`(a != b) & ((a|b) == 0)` has a similar issue but in that case it is less likely
to be an issue as false is almost always just 0 but this changes it to be consistent.

Pushed as obvious after a bootstrap/test on x86_64-linux-gnu.

PR tree-optimization/122296

gcc/ChangeLog:

* match.pd (`(a == b) | ((a|b) != 0)`): Fix true value.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/int-bwise-opt-vect01.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/int-bwise-opt-vect01.c [new file with mode: 0644]

index d41282cc11a6668802378482d93b22769ce5c6df..ab5b51bacaf638c76c0b5ae5951cae7da02a05e9 100644 (file)
@@ -6854,10 +6854,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (eq @0 @1))
 (simplify
  (bit_and:c (ne:c @0 @1) (eq (bit_ior @0 @1) integer_zerop))
- { build_zero_cst (type); })
+ { constant_boolean_node (false, type); })
 (simplify
  (bit_ior:c (eq:c @0 @1) (ne (bit_ior @0 @1) integer_zerop))
- { build_one_cst (type); })
+ { constant_boolean_node (true, type); })
 #endif
 
 /* These was part of minmax phiopt.  */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/int-bwise-opt-vect01.c b/gcc/testsuite/gcc.dg/tree-ssa/int-bwise-opt-vect01.c
new file mode 100644 (file)
index 0000000..bdcdbcc
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop1 -fdump-tree-optimized" } */
+
+/* PR tree-optimization/122296 */
+
+typedef unsigned type1 __attribute__((vector_size(sizeof(unsigned))));
+
+type1 f(type1 a, type1 b)
+{
+  type1 c = a == b;
+  type1 d = (a|b) != 0;
+  return c | d;
+}
+
+/* { dg-final { scan-tree-dump-not "VEC_COND_EXPR " "optimized" } } */
+/* { dg-final { scan-tree-dump-not "VEC_COND_EXPR " "forwprop1" } } */
+