]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/114070 - VEC_COND_EXPR folding
authorRichard Biener <rguenther@suse.de>
Thu, 29 Feb 2024 08:22:19 +0000 (09:22 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 21 Mar 2024 11:48:59 +0000 (12:48 +0100)
The following amends the PR114070 fix to optimistically allow
the folding when we cannot expand the current vec_cond using
vcond_mask and we're still before vector lowering.  This leaves
a small window between vectorization and lowering where we could
break vec_conds that can be expanded via vcond{,u,eq}, most
susceptible is the loop unrolling pass which applies VN and thus
possibly folding to the unrolled body of a vectorized loop.

This gets back the folding for targets that cannot do vectorization.
It doesn't get back the folding for x86 with AVX512 for example
since that can handle the original IL but not the folded since
it misses some vcond_mask expanders.

PR middle-end/114070
* match.pd ((c ? a : b) op d  -->  c ? (a op d) : (b op d)):
Allow the folding if before lowering and the current IL
isn't supported with vcond_mask.

(cherry picked from commit f9c30ea737b806caac917d8f501305151a2cbd57)

gcc/match.pd

index 18a523fe9a8aa12535303f5b6560caee2ec8ce95..908959de3e7f4ece01827a3676d85e5c89a53a83 100644 (file)
@@ -4464,7 +4464,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (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))
+       || 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) */
@@ -4472,13 +4478,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (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))
+       || 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))
+       || 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