]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/117086 - fixup vec_cond simplifications
authorRichard Biener <rguenther@suse.de>
Fri, 11 Oct 2024 09:46:45 +0000 (11:46 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 11 Oct 2024 10:35:23 +0000 (12:35 +0200)
The following adds missing checks for a vector type result type
to simplifications that end up creating a vec_cond.

PR middle-end/117086
* match.pd ((op (vec_cond ...) ..) -> (vec_cond ...)): Add
missing checks for VECTOR_TYPE_P (type).

* gcc.dg/torture/pr117086.c: New testcase.

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

index 5138eec577b0218ed92bfda2bab0d890b9d74e37..5ed1ea03305322c443776950fe44936f08860941 100644 (file)
@@ -5699,35 +5699,38 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* (c ? a : b) op (c ? d : e)  -->  c ? (a op d) : (b op e) */
  (simplify
   (op (vec_cond:s @0 @1 @2) (vec_cond:s @0 @3 @4))
-  (if (TREE_CODE_CLASS (op) != tcc_comparison
-       || types_match (type, TREE_TYPE (@1))
-       || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)
-       || (optimize_vectors_before_lowering_p ()
-          /* The following is optimistic on the side of non-support, we are
-             missing the legacy vcond{,u,eq} cases.  Do this only when
-             lowering will be able to fixup..  */
-          && !expand_vec_cond_expr_p (TREE_TYPE (@1),
-                                      TREE_TYPE (@0), ERROR_MARK)))
+  (if (VECTOR_TYPE_P (type)
+       && (TREE_CODE_CLASS (op) != tcc_comparison
+          || types_match (type, TREE_TYPE (@1))
+          || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)
+          || (optimize_vectors_before_lowering_p ()
+              /* The following is optimistic on the side of non-support, we are
+                 missing the legacy vcond{,u,eq} cases.  Do this only when
+                 lowering will be able to fixup..  */
+              && !expand_vec_cond_expr_p (TREE_TYPE (@1),
+                                          TREE_TYPE (@0), ERROR_MARK))))
    (vec_cond @0 (op! @1 @3) (op! @2 @4))))
 
 /* (c ? a : b) op d  -->  c ? (a op d) : (b op d) */
  (simplify
   (op (vec_cond:s @0 @1 @2) @3)
-  (if (TREE_CODE_CLASS (op) != tcc_comparison
-       || types_match (type, TREE_TYPE (@1))
-       || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)
-       || (optimize_vectors_before_lowering_p ()
-          && !expand_vec_cond_expr_p (TREE_TYPE (@1),
-                                      TREE_TYPE (@0), ERROR_MARK)))
+  (if (VECTOR_TYPE_P (type)
+       && (TREE_CODE_CLASS (op) != tcc_comparison
+          || types_match (type, TREE_TYPE (@1))
+          || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)
+          || (optimize_vectors_before_lowering_p ()
+              && !expand_vec_cond_expr_p (TREE_TYPE (@1),
+                                          TREE_TYPE (@0), ERROR_MARK))))
    (vec_cond @0 (op! @1 @3) (op! @2 @3))))
  (simplify
   (op @3 (vec_cond:s @0 @1 @2))
-  (if (TREE_CODE_CLASS (op) != tcc_comparison
-       || types_match (type, TREE_TYPE (@1))
-       || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)
-       || (optimize_vectors_before_lowering_p ()
-          && !expand_vec_cond_expr_p (TREE_TYPE (@1),
-                                      TREE_TYPE (@0), ERROR_MARK)))
+  (if (VECTOR_TYPE_P (type)
+       && (TREE_CODE_CLASS (op) != tcc_comparison
+          || types_match (type, TREE_TYPE (@1))
+          || expand_vec_cond_expr_p (type, TREE_TYPE (@0), ERROR_MARK)
+          || (optimize_vectors_before_lowering_p ()
+              && !expand_vec_cond_expr_p (TREE_TYPE (@1),
+                                          TREE_TYPE (@0), ERROR_MARK))))
    (vec_cond @0 (op! @3 @1) (op! @3 @2)))))
 
 #if GIMPLE
diff --git a/gcc/testsuite/gcc.dg/torture/pr117086.c b/gcc/testsuite/gcc.dg/torture/pr117086.c
new file mode 100644 (file)
index 0000000..cee19c9
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=znver5" { target { x86_64-*-* i?86-*-* } } } */
+
+void fancy_abort(const char *, int, const char *);
+int usage_insns_0_0;
+void inherit_in_ebb() {
+  int abis = 0;
+  for (int i = 0; i < 8; ++i)
+    if (i > usage_insns_0_0)
+      abis |= i;
+  abis ? fancy_abort("", 0, __FUNCTION__), 0 : 0;
+}