[3/4] match.pd: Teach forwprop to handle VLA VEC_PERM_EXPRs with VLS CONSTRUCTORs as arguments

Message ID 69a0dc52-4125-1d25-fa2b-4acf6cc3b80f@arm.com
State New, archived
Headers
Series aarch64: Improve codegen for dups and constructors |

Commit Message

Andre Vieira (lists) Aug. 5, 2022, 12:56 p.m. UTC
  Hi,

This patch is part of the WIP patch that follows in this series. It's 
goal is to teach forwprop to handle VLA VEC_PERM_EXPRs with VLS 
CONSTRUCTORs as arguments as preparation for the 'VLA constructor' hook 
approach.

Kind Regards,
Andre
  

Comments

Prathamesh Kulkarni Aug. 5, 2022, 2:53 p.m. UTC | #1
On Fri, 5 Aug 2022 at 18:26, Andre Vieira (lists)
<andre.simoesdiasvieira@arm.com> wrote:
>
> Hi,
>
> This patch is part of the WIP patch that follows in this series. It's
> goal is to teach forwprop to handle VLA VEC_PERM_EXPRs with VLS
> CONSTRUCTORs as arguments as preparation for the 'VLA constructor' hook
> approach.

      /* Shuffle of a constructor.  */
       bool ret = false;
-      tree res_type = TREE_TYPE (arg0);
+      tree res_type = TREE_TYPE (gimple_get_lhs (stmt));
       tree opt = fold_ternary (VEC_PERM_EXPR, res_type, arg0, arg1, op2);
       if (!opt
         || (TREE_CODE (opt) != CONSTRUCTOR && TREE_CODE (opt) != VECTOR_CST))

This has to be TREE_TYPE (arg0). I had changed it to TREE_TYPE
(gimple_assign_lhs (stmt)) and it caused
several ICE's on ppc64le (PR106360)
For details, see:
https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598611.html
I currently have a patch in review that extends fold_vec_perm to
handle differing vector lengths:
https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599126.html

Thanks,
Prathamesh
>
> Kind Regards,
> Andre
  

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 9736393061aac61d4d53aaad6cf6b2c97a7d4679..3c3c0c6a88b35a6e42c506f6c4603680fe6e4318 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7852,14 +7852,24 @@  and,
     if (!tree_to_vec_perm_builder (&builder, op2))
       return NULL_TREE;
 
+    /* FIXME: disable folding of a VEC_PERM_EXPR with a VLA mask and VLS
+       CONSTRUCTORS, since that would yield a VLA CONSTRUCTOR which we
+       currently do not support.  */
+    if (!TYPE_VECTOR_SUBPARTS (type).is_constant ()
+	&& (TYPE_VECTOR_SUBPARTS (TREE_TYPE (op0)).is_constant ()
+	    || TYPE_VECTOR_SUBPARTS (TREE_TYPE (op1)).is_constant ()))
+      return NULL_TREE;
+
     /* Create a vec_perm_indices for the integer vector.  */
     poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (type);
     bool single_arg = (op0 == op1);
     vec_perm_indices sel (builder, single_arg ? 1 : 2, nelts);
   }
-  (if (sel.series_p (0, 1, 0, 1))
+  (if (sel.series_p (0, 1, 0, 1)
+       && useless_type_conversion_p (type, TREE_TYPE (op0)))
    { op0; }
-   (if (sel.series_p (0, 1, nelts, 1))
+   (if (sel.series_p (0, 1, nelts, 1)
+	&& useless_type_conversion_p (type, TREE_TYPE (op1)))
     { op1; }
     (with
      {
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index fdc4bc8909d2763876550e53277ff2b3dcca796a..cda91c21c476ea8611e12c593bfa64e1d71dd29e 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2661,7 +2661,7 @@  simplify_permutation (gimple_stmt_iterator *gsi)
 
       /* Shuffle of a constructor.  */
       bool ret = false;
-      tree res_type = TREE_TYPE (arg0);
+      tree res_type = TREE_TYPE (gimple_get_lhs (stmt));
       tree opt = fold_ternary (VEC_PERM_EXPR, res_type, arg0, arg1, op2);
       if (!opt
 	  || (TREE_CODE (opt) != CONSTRUCTOR && TREE_CODE (opt) != VECTOR_CST))