public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237]
@ 2024-01-07 17:29 Tamar Christina
  2024-01-07 19:11 ` Toon Moene
  2024-01-09  9:40 ` Richard Biener
  0 siblings, 2 replies; 4+ messages in thread
From: Tamar Christina @ 2024-01-07 17:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther, jlaw

[-- Attachment #1: Type: text/plain, Size: 2670 bytes --]

Hi All,

Builing on top of the previous patch, similar to when we have a single exit if
we have a case where all exits are considered early exits and there are existing
non virtual phi then in order to maintain LCSSA we have to use the existing PHI
variables.  We can't simply clear them and just rebuild them because the order
of the PHIs in the main exit must match the original exit for when we add the
skip_epilog guard.

But the infrastructure is already in place to maintain them, we just have to use
the right value.

Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
and no issues normally and with with --enable-checking=release --enable-lto
--with-build-config=bootstrap-O3 --enable-checking=yes,rtl,extra.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	PR tree-optimization/113237
	* tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Use
	existing LCSSA variable for exit when all exits are early break.

gcc/testsuite/ChangeLog:

	PR tree-optimization/113237
	* gcc.dg/vect/vect-early-break_98-pr113237.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c
new file mode 100644
index 0000000000000000000000000000000000000000..e6d150b571f753e9eb3859f06f62b371817494a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+
+long Perl_pp_split_limit;
+int Perl_block_gimme();
+int Perl_pp_split() {
+  char strend;
+  long iters;
+  int gimme = Perl_block_gimme();
+  while (--Perl_pp_split_limit) {
+    if (gimme)
+      iters++;
+    if (strend)
+      break;
+  }
+  if (iters)
+    return 0;
+}
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 7fd6566341b4893a1e209d1f8ff65d6d180f1190..77649b84f45b9e5dacec2809e0c854c8fcc17ce1 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1700,7 +1700,12 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit,
 	      if (peeled_iters && !virtual_operand_p (new_arg))
 		{
 		  tree tmp_arg = gimple_phi_result (from_phi);
-		  if (!new_phi_args.get (tmp_arg))
+		  /* Similar to the single exit case, If we have an existing
+		     LCSSA variable thread through the original value otherwise
+		     skip it and directly use the final value.  */
+		  if (tree *res = new_phi_args.get (tmp_arg))
+		    new_arg = *res;
+		  else
 		    new_arg = tmp_arg;
 		}
 




-- 

[-- Attachment #2: rb18131.patch --]
[-- Type: text/plain, Size: 1569 bytes --]

diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c
new file mode 100644
index 0000000000000000000000000000000000000000..e6d150b571f753e9eb3859f06f62b371817494a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+/* { dg-require-effective-target vect_early_break } */
+/* { dg-require-effective-target vect_int } */
+
+long Perl_pp_split_limit;
+int Perl_block_gimme();
+int Perl_pp_split() {
+  char strend;
+  long iters;
+  int gimme = Perl_block_gimme();
+  while (--Perl_pp_split_limit) {
+    if (gimme)
+      iters++;
+    if (strend)
+      break;
+  }
+  if (iters)
+    return 0;
+}
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index 7fd6566341b4893a1e209d1f8ff65d6d180f1190..77649b84f45b9e5dacec2809e0c854c8fcc17ce1 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1700,7 +1700,12 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit,
 	      if (peeled_iters && !virtual_operand_p (new_arg))
 		{
 		  tree tmp_arg = gimple_phi_result (from_phi);
-		  if (!new_phi_args.get (tmp_arg))
+		  /* Similar to the single exit case, If we have an existing
+		     LCSSA variable thread through the original value otherwise
+		     skip it and directly use the final value.  */
+		  if (tree *res = new_phi_args.get (tmp_arg))
+		    new_arg = *res;
+		  else
 		    new_arg = tmp_arg;
 		}
 




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

* Re: [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237]
  2024-01-07 17:29 [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237] Tamar Christina
@ 2024-01-07 19:11 ` Toon Moene
  2024-01-08  8:16   ` Tamar Christina
  2024-01-09  9:40 ` Richard Biener
  1 sibling, 1 reply; 4+ messages in thread
From: Toon Moene @ 2024-01-07 19:11 UTC (permalink / raw)
  To: gcc-patches

On 1/7/24 18:29, Tamar Christina wrote:

> gcc/ChangeLog:
> 
> 	PR tree-optimization/113237
> 	* tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Use
> 	existing LCSSA variable for exit when all exits are early break.

Might that be the same error as I got here when building with 
bootstrap-lto and bootstrap-O3:

https://gcc.gnu.org/pipermail/gcc-testresults/2024-January/804807.html

?

-- 
Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands


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

* Re: [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237]
  2024-01-07 19:11 ` Toon Moene
@ 2024-01-08  8:16   ` Tamar Christina
  0 siblings, 0 replies; 4+ messages in thread
From: Tamar Christina @ 2024-01-08  8:16 UTC (permalink / raw)
  To: Toon Moene, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 935 bytes --]

No, that error is fixed by some earlier patches sent early last week that are awaiting review :)

________________________________
From: Toon Moene <toon@moene.org>
Sent: Sunday, January 7, 2024 7:11 PM
To: gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237]

On 1/7/24 18:29, Tamar Christina wrote:

> gcc/ChangeLog:
>
>        PR tree-optimization/113237
>        * tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Use
>        existing LCSSA variable for exit when all exits are early break.

Might that be the same error as I got here when building with
bootstrap-lto and bootstrap-O3:

https://gcc.gnu.org/pipermail/gcc-testresults/2024-January/804807.html

?

--
Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands


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

* Re: [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237]
  2024-01-07 17:29 [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237] Tamar Christina
  2024-01-07 19:11 ` Toon Moene
@ 2024-01-09  9:40 ` Richard Biener
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2024-01-09  9:40 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd, jlaw

On Sun, 7 Jan 2024, Tamar Christina wrote:

> Hi All,
> 
> Builing on top of the previous patch, similar to when we have a single exit if
> we have a case where all exits are considered early exits and there are existing
> non virtual phi then in order to maintain LCSSA we have to use the existing PHI
> variables.  We can't simply clear them and just rebuild them because the order
> of the PHIs in the main exit must match the original exit for when we add the
> skip_epilog guard.
> 
> But the infrastructure is already in place to maintain them, we just have to use
> the right value.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu
> and no issues normally and with with --enable-checking=release --enable-lto
> --with-build-config=bootstrap-O3 --enable-checking=yes,rtl,extra.
> 
> Ok for master?

OK

Richard.

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/113237
> 	* tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Use
> 	existing LCSSA variable for exit when all exits are early break.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR tree-optimization/113237
> 	* gcc.dg/vect/vect-early-break_98-pr113237.c: New test.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..e6d150b571f753e9eb3859f06f62b371817494a3
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_98-pr113237.c
> @@ -0,0 +1,20 @@
> +/* { dg-do compile } */
> +/* { dg-add-options vect_early_break } */
> +/* { dg-require-effective-target vect_early_break } */
> +/* { dg-require-effective-target vect_int } */
> +
> +long Perl_pp_split_limit;
> +int Perl_block_gimme();
> +int Perl_pp_split() {
> +  char strend;
> +  long iters;
> +  int gimme = Perl_block_gimme();
> +  while (--Perl_pp_split_limit) {
> +    if (gimme)
> +      iters++;
> +    if (strend)
> +      break;
> +  }
> +  if (iters)
> +    return 0;
> +}
> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
> index 7fd6566341b4893a1e209d1f8ff65d6d180f1190..77649b84f45b9e5dacec2809e0c854c8fcc17ce1 100644
> --- a/gcc/tree-vect-loop-manip.cc
> +++ b/gcc/tree-vect-loop-manip.cc
> @@ -1700,7 +1700,12 @@ slpeel_tree_duplicate_loop_to_edge_cfg (class loop *loop, edge loop_exit,
>  	      if (peeled_iters && !virtual_operand_p (new_arg))
>  		{
>  		  tree tmp_arg = gimple_phi_result (from_phi);
> -		  if (!new_phi_args.get (tmp_arg))
> +		  /* Similar to the single exit case, If we have an existing
> +		     LCSSA variable thread through the original value otherwise
> +		     skip it and directly use the final value.  */
> +		  if (tree *res = new_phi_args.get (tmp_arg))
> +		    new_arg = *res;
> +		  else
>  		    new_arg = tmp_arg;
>  		}
>  
> 
> 
> 
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

end of thread, other threads:[~2024-01-09  9:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-07 17:29 [PATCH]middle-end: thread through existing LCSSA variable for alternative exits too [PR113237] Tamar Christina
2024-01-07 19:11 ` Toon Moene
2024-01-08  8:16   ` Tamar Christina
2024-01-09  9:40 ` 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).