]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/123575 - fix ABS_EXPR folding for vectors
authorRichard Biener <rguenther@suse.de>
Wed, 28 Jan 2026 12:39:14 +0000 (13:39 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 28 Jan 2026 13:56:22 +0000 (14:56 +0100)
Folding away a conversion requires an optab check for vectors.

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
gcc/testsuite/g++.dg/pr123575.C [new file with mode: 0644]

index d86429f5dd8f1908dc5d1e96b8dbd4913a0bde67..75511c459fa2024ec7d66cc2225d02e4cd16b83f 100644 (file)
@@ -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 (file)
index 0000000..9a06288
--- /dev/null
@@ -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;
+}