public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/108482 - remove stray .LOOP_DIST_ALIAS calls
@ 2023-01-23 10:09 Richard Biener
  2023-01-23 10:20 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2023-01-23 10:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

The following deals with .LOOP_DIST_ALIAS surviving vectorization
because any of the loops involved were elided between loop distribution
and vectorization.  As opposed to .LOOP_VECTORIZED which exists only
between if-conversion and vectorization with no intermediate passes
this is more difficult to deal with in advance and thus cleaning
up after vectorization looks better.  There's the unconditional
vector lowering pass which looks like a good place for this (for
SIMD uid we have pass_simduid_cleanup).

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

OK?

Thanks,
Richard.

	PR tree-optimization/108482
	* tree-vect-generic.cc (expand_vector_operations): Fold remaining
	.LOOP_DIST_ALIAS calls.

	* gcc.dg/torture/pr108482.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr108482.c | 18 ++++++++++++++++++
 gcc/tree-vect-generic.cc                |  8 ++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr108482.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr108482.c b/gcc/testsuite/gcc.dg/torture/pr108482.c
new file mode 100644
index 00000000000..8dc1169a9c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108482.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+int g_30, g_261, g_263, func_1___trans_tmp_17;
+int **g_120;
+int *g_530;
+void func_1() {
+  int *l_29 = &g_30;
+  *l_29 = 1;
+  g_263 = 0;
+  for (; g_263 <= 1; g_263 += 1) {
+    g_530 = 0;
+    if (*l_29) {
+      char *l_1694 = (char *)&g_261;
+      *l_1694 &= **g_120;
+    } else
+      *l_29 ^= func_1___trans_tmp_17;
+  }
+}
diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc
index 2e2d7567293..166a248f4b9 100644
--- a/gcc/tree-vect-generic.cc
+++ b/gcc/tree-vect-generic.cc
@@ -2398,6 +2398,14 @@ expand_vector_operations (void)
 	  if (maybe_clean_eh_stmt (gsi_stmt (gsi))
 	      && gimple_purge_dead_eh_edges (bb))
 	    cfg_changed = true;
+	  /* If a .LOOP_DIST_ALIAS call prevailed loops got elided
+	     before vectorization got a chance to get at them.  Simply
+	     fold as if loop distribution wasn't performed.  */
+	  if (gimple_call_internal_p (gsi_stmt (gsi), IFN_LOOP_DIST_ALIAS))
+	    {
+	      fold_loop_internal_call (gsi_stmt (gsi), boolean_false_node);
+	      cfg_changed = true;
+	    }
 	}
     }
 
-- 
2.35.3

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

* Re: [PATCH] tree-optimization/108482 - remove stray .LOOP_DIST_ALIAS calls
  2023-01-23 10:09 [PATCH] tree-optimization/108482 - remove stray .LOOP_DIST_ALIAS calls Richard Biener
@ 2023-01-23 10:20 ` Jakub Jelinek
  2023-01-23 10:28   ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2023-01-23 10:20 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Mon, Jan 23, 2023 at 11:09:43AM +0100, Richard Biener wrote:
> The following deals with .LOOP_DIST_ALIAS surviving vectorization
> because any of the loops involved were elided between loop distribution
> and vectorization.  As opposed to .LOOP_VECTORIZED which exists only
> between if-conversion and vectorization with no intermediate passes
> this is more difficult to deal with in advance and thus cleaning
> up after vectorization looks better.  There's the unconditional
> vector lowering pass which looks like a good place for this (for
> SIMD uid we have pass_simduid_cleanup).
> 
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> 
> OK?

I admit I didn't know something like LOOP_DIST_ALIAS even exist until
today.
Anyway, I wonder if there is still time to clean up during/after
veclower21.
I see fold_loop_internal_call propagates the return value to immediate
uses and cfg_changed means we'll clean up the cfg, is that enough?

	Jakub


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

* Re: [PATCH] tree-optimization/108482 - remove stray .LOOP_DIST_ALIAS calls
  2023-01-23 10:20 ` Jakub Jelinek
@ 2023-01-23 10:28   ` Richard Biener
  2023-01-23 10:29     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2023-01-23 10:28 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Mon, 23 Jan 2023, Jakub Jelinek wrote:

> On Mon, Jan 23, 2023 at 11:09:43AM +0100, Richard Biener wrote:
> > The following deals with .LOOP_DIST_ALIAS surviving vectorization
> > because any of the loops involved were elided between loop distribution
> > and vectorization.  As opposed to .LOOP_VECTORIZED which exists only
> > between if-conversion and vectorization with no intermediate passes
> > this is more difficult to deal with in advance and thus cleaning
> > up after vectorization looks better.  There's the unconditional
> > vector lowering pass which looks like a good place for this (for
> > SIMD uid we have pass_simduid_cleanup).
> > 
> > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> > 
> > OK?
> 
> I admit I didn't know something like LOOP_DIST_ALIAS even exist until
> today.
> Anyway, I wonder if there is still time to clean up during/after
> veclower21.

That's what the patch does, but maybe I misunderstood the question.

> I see fold_loop_internal_call propagates the return value to immediate
> uses and cfg_changed means we'll clean up the cfg, is that enough?

It's enough to get rid of the internal function call which will ICE
if it reaches RTL expansion.  The earliest point to get rid of them
is in the loop vectorizer but for the testcase at hand this requires
a walk of the whole IL where we cut the whole vectorizer pass with
the number-of-loops in function check currently.

Richard.

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

* Re: [PATCH] tree-optimization/108482 - remove stray .LOOP_DIST_ALIAS calls
  2023-01-23 10:28   ` Richard Biener
@ 2023-01-23 10:29     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-01-23 10:29 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Mon, Jan 23, 2023 at 10:28:01AM +0000, Richard Biener wrote:
> On Mon, 23 Jan 2023, Jakub Jelinek wrote:
> 
> > On Mon, Jan 23, 2023 at 11:09:43AM +0100, Richard Biener wrote:
> > > The following deals with .LOOP_DIST_ALIAS surviving vectorization
> > > because any of the loops involved were elided between loop distribution
> > > and vectorization.  As opposed to .LOOP_VECTORIZED which exists only
> > > between if-conversion and vectorization with no intermediate passes
> > > this is more difficult to deal with in advance and thus cleaning
> > > up after vectorization looks better.  There's the unconditional
> > > vector lowering pass which looks like a good place for this (for
> > > SIMD uid we have pass_simduid_cleanup).
> > > 
> > > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> > > 
> > > OK?
> > 
> > I admit I didn't know something like LOOP_DIST_ALIAS even exist until
> > today.
> > Anyway, I wonder if there is still time to clean up during/after
> > veclower21.
> 
> That's what the patch does, but maybe I misunderstood the question.
> 
> > I see fold_loop_internal_call propagates the return value to immediate
> > uses and cfg_changed means we'll clean up the cfg, is that enough?
> 
> It's enough to get rid of the internal function call which will ICE
> if it reaches RTL expansion.  The earliest point to get rid of them
> is in the loop vectorizer but for the testcase at hand this requires
> a walk of the whole IL where we cut the whole vectorizer pass with
> the number-of-loops in function check currently.

Ok then.

	Jakub


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

end of thread, other threads:[~2023-01-23 10:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-23 10:09 [PATCH] tree-optimization/108482 - remove stray .LOOP_DIST_ALIAS calls Richard Biener
2023-01-23 10:20 ` Jakub Jelinek
2023-01-23 10:28   ` Richard Biener
2023-01-23 10:29     ` Jakub Jelinek

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).