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.
(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)))))
--- /dev/null
+// { 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;
+}