public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Optimize identical permutation in my last r13-3212-gb88adba751da63
@ 2022-10-13  3:15 Liwei Xu
  2022-10-13 10:41 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Liwei Xu @ 2022-10-13  3:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.guenther, wilson, admin, hongtao.liu

Add extra index check when merging VEC_CST, this handles the case when exactly op1 needs to be return.

This fixes:
	FAIL: gcc.dg/tree-ssa/forwprop-19.c scan-tree-dump-not forwprop1 "VEC_PERM_EXPR"

gcc/ChangeLog:

	PR target/107220
	* match.pd: Check the index of VEC_CST and return the op1 if needed.
---
 gcc/match.pd | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 3550c16aaa6..1efdc3abb5d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8106,6 +8106,7 @@ and,
     vec_perm_builder builder0;
     vec_perm_builder builder1;
     vec_perm_builder builder2 (nelts, nelts, 1);
+    bool ident_to_1 = true;
 
     if (!tree_to_vec_perm_builder (&builder0, @3)
 	|| !tree_to_vec_perm_builder (&builder1, @4))
@@ -8115,7 +8116,15 @@ and,
     vec_perm_indices sel1 (builder1, 1, nelts);
 
     for (int i = 0; i < nelts; i++)
-      builder2.quick_push (sel0[sel1[i].to_constant ()]);
+      {
+	 int tmp_index = sel0[sel1[i].to_constant ()].to_constant ();
+	 builder2.quick_push (sel0[sel1[i].to_constant ()]);
+	 if ( i != tmp_index)
+	  ident_to_1 = false;
+      }
+
+    if (ident_to_1)
+      return @1;
 
     vec_perm_indices sel2 (builder2, 2, nelts);
 
-- 
2.18.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Optimize identical permutation in my last r13-3212-gb88adba751da63
  2022-10-13  3:15 [PATCH] Optimize identical permutation in my last r13-3212-gb88adba751da63 Liwei Xu
@ 2022-10-13 10:41 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-10-13 10:41 UTC (permalink / raw)
  To: Liwei Xu; +Cc: gcc-patches, wilson, admin, hongtao.liu

On Thu, Oct 13, 2022 at 5:15 AM Liwei Xu <liwei.xu@intel.com> wrote:
>
> Add extra index check when merging VEC_CST, this handles the case when exactly op1 needs to be return.
>
> This fixes:
>         FAIL: gcc.dg/tree-ssa/forwprop-19.c scan-tree-dump-not forwprop1 "VEC_PERM_EXPR"
>
> gcc/ChangeLog:
>
>         PR target/107220
>         * match.pd: Check the index of VEC_CST and return the op1 if needed.
> ---
>  gcc/match.pd | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 3550c16aaa6..1efdc3abb5d 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -8106,6 +8106,7 @@ and,
>      vec_perm_builder builder0;
>      vec_perm_builder builder1;
>      vec_perm_builder builder2 (nelts, nelts, 1);
> +    bool ident_to_1 = true;
>
>      if (!tree_to_vec_perm_builder (&builder0, @3)
>         || !tree_to_vec_perm_builder (&builder1, @4))
> @@ -8115,7 +8116,15 @@ and,
>      vec_perm_indices sel1 (builder1, 1, nelts);
>
>      for (int i = 0; i < nelts; i++)
> -      builder2.quick_push (sel0[sel1[i].to_constant ()]);
> +      {
> +        int tmp_index = sel0[sel1[i].to_constant ()].to_constant ();
> +        builder2.quick_push (sel0[sel1[i].to_constant ()]);
> +        if ( i != tmp_index)
> +         ident_to_1 = false;
> +      }
> +
> +    if (ident_to_1)
> +      return @1;

You can't "return" in match.pd code.  I think the code was fine and the testcase
can be adjusted to scan the subsequent DSE or DCE pass instead.

The "correct" match.pd approach would be to do the if (ident_to_1) check here:

@@ -8124,7 +8124,9 @@ and,

     op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2);
   }
-  (vec_perm @1 @2 { op0; })))
+  (if (ident_to_1)
+   @1
+   (vec_perm @1 @2 { op0; }))))

I'll see to reject 'return' in c-exprs ;)

Richard.

>
>      vec_perm_indices sel2 (builder2, 2, nelts);
>
> --
> 2.18.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-13 10:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-13  3:15 [PATCH] Optimize identical permutation in my last r13-3212-gb88adba751da63 Liwei Xu
2022-10-13 10:41 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).