]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/114070 - folding breaking VEC_COND expansion
authorRichard Biener <rguenther@suse.de>
Fri, 23 Feb 2024 15:06:05 +0000 (16:06 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 21 Mar 2024 11:48:58 +0000 (12:48 +0100)
The following properly guards the simplifications that move
operations into VEC_CONDs, in particular when that changes the
type constraints on this operation.

This needed a genmatch fix which was recording spurious implicit fors
when tcc_comparison is used in a C expression.

PR middle-end/114070
* genmatch.cc (parser::parse_c_expr): Do not record operand
lists but only mark operators used.
* match.pd ((c ? a : b) op (c ? d : e)  -->  c ? (a op d) : (b op e)):
Properly guard the case of tcc_comparison changing the VEC_COND
value operand type.

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

(cherry picked from commit af66ad89e8169f44db723813662917cf4cbb78fc)

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

index 98b429a9d0bb3130246e375a9cef46528f0f9467..c1023d921fca69aaea591bc79d500819994e2f32 100644 (file)
@@ -4519,10 +4519,8 @@ parser::parse_c_expr (cpp_ttype start)
            = (const char *)CPP_HASHNODE (token->val.node.node)->ident.str;
          if (strcmp (str, "return") == 0)
            fatal_at (token, "return statement not allowed in C expression");
-         id_base *idb = get_operator (str);
-         user_id *p;
-         if (idb && (p = dyn_cast<user_id *> (idb)) && p->is_oper_list)
-           record_operlist (token->src_loc, p);
+         /* Mark user operators corresponding to 'str' as used.  */
+         get_operator (str);
        }
 
       /* Record the token.  */
index 8e41c973dc2825fb066c29757d1b2a351ea64504..18a523fe9a8aa12535303f5b6560caee2ec8ce95 100644 (file)
@@ -4462,15 +4462,24 @@ 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))
-  (vec_cond @0 (op! @1 @3) (op! @2 @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))
+   (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)
-  (vec_cond @0 (op! @1 @3) (op! @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))
+   (vec_cond @0 (op! @1 @3) (op! @2 @3))))
  (simplify
   (op @3 (vec_cond:s @0 @1 @2))
-  (vec_cond @0 (op! @3 @1) (op! @3 @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))
+   (vec_cond @0 (op! @3 @1) (op! @3 @2)))))
 
 #if GIMPLE
 (match (nop_atomic_bit_test_and_p @0 @1 @4)
diff --git a/gcc/testsuite/gcc.dg/torture/pr114070.c b/gcc/testsuite/gcc.dg/torture/pr114070.c
new file mode 100644 (file)
index 0000000..cf46ec4
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-vect-cost-model" } */
+
+int unresolved(unsigned dirmask, unsigned mask, int *unresolved_n)
+{
+  for (int i = 0; i < 1024; i++) {
+    mask |= 1;
+    if (!unresolved_n[i] || unresolved_n[i] & 70000)
+      dirmask |= 1;
+  }
+  return (dirmask == mask);
+}