Folding away a conversion requires an optab check for vectors.

Bootstrapped and tested on x86-64-unknown-linux-gnu, pushed.

        PR middle-end/123575
        * match.pd (abs ((T)x) -> absu (x)): For vector type
        arguments require the resulting operation is supported.

        * g++.dg/pr123575.C: New testcase.
---
 gcc/match.pd                    |  4 +++-
 gcc/testsuite/g++.dg/pr123575.C | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/pr123575.C

diff --git a/gcc/match.pd b/gcc/match.pd
index d86429f5dd8..75511c459fa 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -214,7 +214,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 (simplify (abs (convert @0))
  (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
       && !TYPE_UNSIGNED (TREE_TYPE (@0))
-      && element_precision (type) > element_precision (TREE_TYPE (@0)))
+      && element_precision (type) > element_precision (TREE_TYPE (@0))
+      && (!VECTOR_TYPE_P (type)
+         || target_supports_op_p (TREE_TYPE (@0), ABSU_EXPR, optab_vector)))
   (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
    (convert (absu:utype @0)))))
 
diff --git a/gcc/testsuite/g++.dg/pr123575.C b/gcc/testsuite/g++.dg/pr123575.C
new file mode 100644
index 00000000000..9a062885106
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr123575.C
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "-O -Wno-psabi" }
+
+typedef int __attribute__((vector_size(sizeof(int)*2))) v2i;
+typedef long __attribute__((vector_size(sizeof(long)*2))) v2l;
+
+v2l f(v2i a)
+{
+  v2l  t = __builtin_convertvector(a, v2l);
+  t = t > 0 ? t : -t;
+  return t;
+}
-- 
2.51.0

Reply via email to