[gcc(refs/vendors/vrull/heads/slp-improvements)] match.pd: Look through view_convert when folding vec_perms

Philipp Tomsich ptomsich@gcc.gnu.org
Wed Jan 17 19:14:00 GMT 2024


https://gcc.gnu.org/g:89a6e3d55d5b4422f6be334cfd8ea4127917068f

commit 89a6e3d55d5b4422f6be334cfd8ea4127917068f
Author: Manolis Tsamis <manolis.tsamis@vrull.eu>
Date:   Wed Nov 1 12:27:28 2023 +0100

    match.pd: Look through view_convert when folding vec_perms
    
    The match.pd patterns to merge two vector permutes into one fail to
    match when a (potentially no-op) view convert expressions is
    separating the two permutes.  This is observable in the SLP tree for
    the first loop of x264's satd and inhibits optimization.
    
    This change adds a check whether a view_convert will be a no-op
    (comparing the element precision) and rewrites the permute sequence
    for those cases.
    
    Ref #343

Diff:
---
 gcc/match.pd | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 7b4b15acc41..59a664293ea 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -9929,7 +9929,7 @@ and,
      d = VEC_PERM_EXPR <a, b, NEW_VCST>;  */
 
 (simplify
- (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4)
+ (vec_perm (view_convert?@0 (vec_perm @1 @2 VECTOR_CST@3)) @0 VECTOR_CST@4)
  (if (TYPE_VECTOR_SUBPARTS (type).is_constant ())
   (with
    {
@@ -9941,7 +9941,8 @@ and,
      vec_perm_builder builder2 (nelts, nelts, 1);
    }
    (if (tree_to_vec_perm_builder (&builder0, @3)
-	&& tree_to_vec_perm_builder (&builder1, @4))
+	&& tree_to_vec_perm_builder (&builder1, @4)
+	&& element_precision (type) == element_precision (TREE_TYPE (@0)))
     (with
      {
        vec_perm_indices sel0 (builder0, 2, nelts);
@@ -9966,7 +9967,7 @@ and,
 	 op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
      }
      (if (op0)
-      (vec_perm @1 @2 { op0; })))))))
+      (view_convert (vec_perm @1 @2 { op0; }))))))))
 
 /* Merge
      c = VEC_PERM_EXPR <a, b, VCST0>;


More information about the Gcc-cvs mailing list