]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: don't lower past veclower [PR106063]
authorTamar Christina <tamar.christina@arm.com>
Fri, 8 Jul 2022 07:30:22 +0000 (08:30 +0100)
committerTamar Christina <tamar.christina@arm.com>
Fri, 8 Jul 2022 07:30:22 +0000 (08:30 +0100)
Hi All,

My previous patch can cause a problem if the pattern matches after veclower
as it may replace the construct with a vector sequence which the target may not
directly support.

As such don't perform the rewriting if after veclower unless the target supports
the operation.  If before veclower do the rewriting as well if the target didn't
support the original operation either.

gcc/ChangeLog:

PR tree-optimization/106063
* match.pd: Do not apply pattern after veclower is not supported.

gcc/testsuite/ChangeLog:

PR tree-optimization/106063
* gcc.dg/pr106063.c: New test.

gcc/match.pd
gcc/testsuite/gcc.dg/pr106063.c [new file with mode: 0644]

index c43c528424e3167307c0d5c25fc11ff79ff6d186..6603f29f58ab2176c2a032ad9afd0fef81a10959 100644 (file)
@@ -6008,10 +6008,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
    (cmp (bit_and:c@2 @0 cst@1) integer_zerop)
     (with { tree csts = bitmask_inv_cst_vector_p (@1); }
      (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2)))
-      (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
-       (icmp @0 { csts; })
-       (with { tree utype = unsigned_type_for (TREE_TYPE (@1)); }
-        (icmp (view_convert:utype @0) { csts; }))))))))
+      (with { auto optab = VECTOR_TYPE_P (TREE_TYPE (@1))
+                        ? optab_vector : optab_default;
+             tree utype = unsigned_type_for (TREE_TYPE (@1)); }
+       (if (target_supports_op_p (utype, icmp, optab)
+           || (optimize_vectors_before_lowering_p ()
+               && (!target_supports_op_p (type, cmp, optab)
+                   || !target_supports_op_p (type, BIT_AND_EXPR, optab))))
+       (if (TYPE_UNSIGNED (TREE_TYPE (@1)))
+        (icmp @0 { csts; })
+        (icmp (view_convert:utype @0) { csts; })))))))))
 
 /* When one argument is a constant, overflow detection can be simplified.
    Currently restricted to single use so as not to interfere too much with
diff --git a/gcc/testsuite/gcc.dg/pr106063.c b/gcc/testsuite/gcc.dg/pr106063.c
new file mode 100644 (file)
index 0000000..b235967
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-forwprop --disable-tree-evrp" } */
+typedef __int128 __attribute__((__vector_size__ (16))) V;
+
+V
+foo (V v)
+{
+  return (v & (V){15}) == v;
+}