aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-10-12 14:51:37 +0200
committerRichard Biener <rguenth@gcc.gnu.org>2024-10-12 17:04:31 +0200
commitf54d42e00007e7a558b273d87f95b3e5b1938f5a (patch)
treeedd7de0ce2e0fd0a9a6f93451bb030959ed98d53
parentba773a86f0377abccecd3e398dceb9408bba5a7c (diff)
downloadgcc-f54d42e00007e7a558b273d87f95b3e5b1938f5a.zip
gcc-f54d42e00007e7a558b273d87f95b3e5b1938f5a.tar.gz
gcc-f54d42e00007e7a558b273d87f95b3e5b1938f5a.tar.bz2
tree-optimization/117104 - add missed guards to max(a,b) != a simplification
For vector types we have to make sure the comparison result is a vector type and the resulting compare operation is supported. As the resulting compare is never an equality compare I didn't bother to check for the cbranch case. PR tree-optimization/117104 * match.pd ((cmp:c (minmax:c @0 @1) @0) -> (out @0 @1)): Properly guard the vector case. * gcc.dg/pr117104.c: New testcase.
-rw-r--r--gcc/match.pd6
-rw-r--r--gcc/testsuite/gcc.dg/pr117104.c12
2 files changed, 17 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index f2b5f3a..eff1ace 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4688,7 +4688,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
out (le gt gt le ge lt lt ge )
(simplify
(cmp:c (minmax:c @0 @1) @0)
- (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+ (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && (!VECTOR_TYPE_P (TREE_TYPE (@0))
+ || (VECTOR_TYPE_P (type)
+ && (!expand_vec_cmp_expr_p (TREE_TYPE (@0), type, cmp)
+ || expand_vec_cmp_expr_p (TREE_TYPE (@0), type, out)))))
(out @0 @1))))
/* MIN (X, 5) == 0 -> X == 0
MIN (X, 5) == 7 -> false */
diff --git a/gcc/testsuite/gcc.dg/pr117104.c b/gcc/testsuite/gcc.dg/pr117104.c
new file mode 100644
index 0000000..9aa5734
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117104.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-vect-cost-model" } */
+/* { dg-additional-options "-mavx" { target { x86_64-*-* i?86-*-* } } } */
+
+void g();
+void f(long *a)
+{
+ long b0 = a[0] > 0 ? a[0] : 0;
+ long b1 = a[1] > 0 ? a[1] : 0;
+ if ((b0|b1) == 0)
+ g();
+}