The X | -X matcher of the range-test patterns has no constant operand,
so vectors reach it and the shift form converts a scalar comparison to
a vector type.  As Andrea Pinski suggested, limit it to integral types;
the other matchers are already scalar through their INTEGER_CST.

Bootstrapped on x86_64-pc-linux-gnu; tree-ssa, vect, dg and dg-torture
tests show no regressions.

Assisted-by: Claude Opus 5 (Anthropic)

        PR tree-optimization/127379

gcc/ChangeLog:

        * match.pd (ior_range_test_0): Require an integral type.

gcc/testsuite/ChangeLog:

        * gcc.dg/torture/pr127379.c: New test.

Signed-off-by: Dominic P <[email protected]>
---
 gcc/match.pd                            |  3 ++-
 gcc/testsuite/gcc.dg/torture/pr127379.c | 29 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr127379.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 0d2312c17f7..4059ed787f0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5129,7 +5129,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       && wi::ge_p (wi::to_wide (@1), 0, SIGNED))))
 (match (ior_range_test_0 @0)
  (bit_ior:c@1 @0 (negate @0))
- (if (single_use (@1)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+      && single_use (@1)
       && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@0)))))
 (for cmp (lt ge)
      out (gt le)
diff --git a/gcc/testsuite/gcc.dg/torture/pr127379.c 
b/gcc/testsuite/gcc.dg/torture/pr127379.c
new file mode 100644
index 00000000000..94acd2ad04a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr127379.c
@@ -0,0 +1,29 @@
+/* PR tree-optimization/127379 */
+/* { dg-do compile } */
+/* { dg-require-effective-target int32 } */
+/* { dg-additional-options "-Wno-psabi" } */
+
+__attribute__((vector_size (sizeof (unsigned))))
+  unsigned v1;
+int a;
+
+int
+f (void)
+{
+  return (a | (v1 | -v1) >> 31)[0];
+}
+
+typedef unsigned int vu __attribute__ ((vector_size (16)));
+typedef int vi __attribute__ ((vector_size (16)));
+
+vu
+g (vu x)
+{
+  return (x | -x) >> 31;
+}
+
+vu
+h (vi x)
+{
+  return (vu) (x | -x) >> 31;
+}
-- 
2.55.0

Reply via email to