]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match: Fix merged patterns for a!=b implies a and b are not zero [PR125234]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 8 May 2026 19:46:32 +0000 (12:46 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 9 May 2026 01:02:28 +0000 (18:02 -0700)
In r17-231-gc65691bc5a2873, I messed up the resulting constant for
`(a != b) & ((a | b) == 0)` and `(a == b) | ((a | b) != 0)`. I had
swapped which one was resulting in true/false. This fixes the issue
and adds a testcase to make sure it does not regress again.

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

PR tree-optimization/125234

gcc/ChangeLog:

* match.pd (`(a !=/== b) &\| ((a|b) ==/!= 0)`): Fix
resulting constant form.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr125234-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr125234-1.c [new file with mode: 0644]

index 494e26a7d49af430fe2f4b0d4ff4f859541fd111..198e2e7202e82f9cf5e9e5aa0f535db73171815a 100644 (file)
@@ -7197,7 +7197,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      neeqr (eq      ne)
  (simplify
   (bitop (neeql @0 @1) (neeqr (bit_ior @0 @1) integer_zerop))
-  { constant_boolean_node (bitop==BIT_AND_EXPR, type); }))
+  { constant_boolean_node (bitop == BIT_IOR_EXPR, type); }))
 #endif
 
 /* These was part of minmax phiopt.  */
diff --git a/gcc/testsuite/gcc.dg/torture/pr125234-1.c b/gcc/testsuite/gcc.dg/torture/pr125234-1.c
new file mode 100644 (file)
index 0000000..70854ea
--- /dev/null
@@ -0,0 +1,49 @@
+/* PR tree-optimization/125234 */
+/* { dg-do run } */
+
+__attribute__((noinline))
+int f0(int a, int b)
+{
+  return (a != b) & ((a | b) == 0);
+}
+
+__attribute__((noinline))
+int f1(int a, int b)
+{
+  return (a == b) | ((a | b) != 0);
+}
+
+
+__attribute__((noinline))
+int f0_(int a, int b)
+{
+  if (a != b)
+    if ((a | b) == 0)
+      return 1;
+  return 0;
+}
+
+__attribute__((noinline))
+int f1_(int a, int b)
+{
+  if (a == b)
+    return 1;
+  if ((a | b) != 0)
+    return 1;
+  return 0;
+}
+
+
+int
+main()
+{
+  if (f0(0, 0))
+    __builtin_abort ();
+  if (!f1(0, 0))
+    __builtin_abort ();
+  if (f0_(0, 0))
+    __builtin_abort ();
+  if (!f1_(0, 0))
+    __builtin_abort ();
+}
+