]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match: Fix `(A>>bool) EQ 0 -> (unsigned)A LE bool` pattern for vector types [PR125139]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 1 May 2026 23:09:30 +0000 (16:09 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Sat, 2 May 2026 01:36:38 +0000 (18:36 -0700)
This pattern does not work for vector types as written. To make it work we need to
create a vec_duplicate of the `bool` value.  I am not sure that is better so for
right now this just enables the pattern only for INTEGRAL_TYPE_P types (which means
non-vectors).

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

PR tree-optimization/125139

gcc/ChangeLog:

* match.pd (`(A>>bool) EQ 0 -> (unsigned)A LE bool`): Enable
only for INTEGRAL_TYPE_P types.

gcc/testsuite/ChangeLog:

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

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

index 5fed1419bdb30e841e8927b5f79755a7f3389a3a..dd9efb82c59dc215ce8b7b3d43a79dbbbd04b0c2 100644 (file)
@@ -5447,7 +5447,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
      icmp (le gt)
  (simplify
   (cmp (rshift@2 @0 zero_one_valued_p@1) integer_zerop)
-  (if (single_use (@2))
+  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && single_use (@2))
    (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
     (icmp (convert:utype @0) (convert:utype @1))))))
 #endif
diff --git a/gcc/testsuite/gcc.dg/torture/pr125139-1.c b/gcc/testsuite/gcc.dg/torture/pr125139-1.c
new file mode 100644 (file)
index 0000000..8a67e7c
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+typedef __attribute__((vector_size(4*sizeof(int)))) int v4int;
+
+void f(v4int *v, int a)
+{
+  a &= 1;
+  *v = *v >> a;
+  *v = *v == 0;
+}