Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Aldy Hernandez via Gcc
On 9/10/21 6:21 PM, Jeff Law wrote: On 9/10/2021 10:05 AM, Aldy Hernandez wrote: On 9/10/21 5:43 PM, Jeff Law wrote: On 9/9/2021 3:21 AM, Aldy Hernandez wrote:    /* If this path does not thread through the loop latch, then we are   using the FSM threader to find old style jump

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Jeff Law via Gcc
On 9/10/2021 10:05 AM, Aldy Hernandez wrote: On 9/10/21 5:43 PM, Jeff Law wrote: On 9/9/2021 3:21 AM, Aldy Hernandez wrote:    /* If this path does not thread through the loop latch, then we are   using the FSM threader to find old style jump threads. This   is good, except th

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Aldy Hernandez via Gcc
On 9/10/21 5:51 PM, Jeff Law wrote: On 9/9/2021 4:15 AM, Richard Biener wrote: b) Even though we can seemingly fold everything DOM/threader does, in order to replace it with a backward threader instance we'd have to merge the cost/profitability code scattered throughout the forward thread

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Aldy Hernandez via Gcc
On 9/10/21 5:43 PM, Jeff Law wrote: On 9/9/2021 3:21 AM, Aldy Hernandez wrote:    /* If this path does not thread through the loop latch, then we are   using the FSM threader to find old style jump threads. This   is good, except the FSM threader does not re-use an existing  

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Jeff Law via Gcc
On 9/9/2021 4:15 AM, Richard Biener wrote: b) Even though we can seemingly fold everything DOM/threader does, in order to replace it with a backward threader instance we'd have to merge the cost/profitability code scattered throughout the forward threader, as well as the EDGE_FSM* / EDGE_COP

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Jeff Law via Gcc
On 9/9/2021 3:21 AM, Aldy Hernandez wrote:    /* If this path does not thread through the loop latch, then we are   using the FSM threader to find old style jump threads. This   is good, except the FSM threader does not re-use an existing   threading path to reduce code duplicat

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-10 Thread Aldy Hernandez via Gcc
I think things are clear enough to propose a patch. Thanks for everyone's input. I have added some comments and tweaked Michael's patch to include the final BB where we're threading to, in the check. Without this last check, we fail in tree-ssa/cunroll-15.c because the latch becomes pollute

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Jeff Law via Gcc
On 9/9/2021 2:58 AM, Richard Biener wrote: On Thu, Sep 9, 2021 at 10:36 AM Aldy Hernandez wrote: On 9/9/21 9:45 AM, Richard Biener wrote: On Thu, Sep 9, 2021 at 9:37 AM Aldy Hernandez wrote: On 9/9/21 8:57 AM, Richard Biener wrote: On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote:

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Jeff Law via Gcc
On 9/9/2021 2:14 AM, Aldy Hernandez wrote: On 9/8/21 8:13 PM, Michael Matz wrote: Hello, [lame answer to self] On Wed, 8 Sep 2021, Michael Matz wrote: The forward threader guards against this by simply disallowing threadings that involve different loops.  As I see The thread in questi

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/9/21 4:44 PM, Michael Matz wrote: Hello, On Thu, 9 Sep 2021, Aldy Hernandez wrote: Here there's no simple latch block to start with (the backedge comes directly out of the loop exit block). So my suggested improvement (testing if the latch was empty and only then reject the thread), w

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Michael Matz via Gcc
Hello, On Thu, 9 Sep 2021, Aldy Hernandez wrote: > > Here there's no simple latch block to start with (the backedge comes > > directly out of the loop exit block). So my suggested improvement > > (testing if the latch was empty and only then reject the thread), would > > solve this. > > Well, t

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/9/21 2:52 PM, Michael Matz wrote: Hello, On Thu, 9 Sep 2021, Aldy Hernandez wrote: The ldist-22 regression is interesting though: void foo () { int i; : goto ; [INV] : a[i_1] = 0; if (i_1 > 100) goto ; [INV] else goto ; [INV] : b[i_1] = i_1;

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Michael Matz via Gcc
Hello, On Thu, 9 Sep 2021, Aldy Hernandez wrote: > The ldist-22 regression is interesting though: > > void foo () > { > int i; > >: > goto ; [INV] > >: > a[i_1] = 0; > if (i_1 > 100) > goto ; [INV] > else > goto ; [INV] > >: > b[i_1] = i_1; > >: > i_8 =

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Michael Matz via Gcc
Hello, On Thu, 9 Sep 2021, Richard Biener wrote: > > I believe something like below would be appropriate, it disables > > threading if the path contains a latch at the non-last position (due > > to being backwards on the non-first position in the array). I.e. it > > disables rotating the loop

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/9/21 12:15 PM, Richard Biener wrote: On Thu, Sep 9, 2021 at 11:21 AM Aldy Hernandez wrote: On 9/9/21 10:58 AM, Richard Biener wrote: I ran some experiments a while back, and my current work on the enhanced solver/threader, can fold virtually everything the DOM/threader gets (even wit

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Richard Biener via Gcc
On Thu, Sep 9, 2021 at 11:21 AM Aldy Hernandez wrote: > > > > On 9/9/21 10:58 AM, Richard Biener wrote: > > On Thu, Sep 9, 2021 at 10:36 AM Aldy Hernandez wrote: > >> > >> > >> > >> On 9/9/21 9:45 AM, Richard Biener wrote: > >>> On Thu, Sep 9, 2021 at 9:37 AM Aldy Hernandez wrote: > >

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/9/21 10:58 AM, Richard Biener wrote: On Thu, Sep 9, 2021 at 10:36 AM Aldy Hernandez wrote: On 9/9/21 9:45 AM, Richard Biener wrote: On Thu, Sep 9, 2021 at 9:37 AM Aldy Hernandez wrote: On 9/9/21 8:57 AM, Richard Biener wrote: On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote:

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Richard Biener via Gcc
On Thu, Sep 9, 2021 at 10:36 AM Aldy Hernandez wrote: > > > > On 9/9/21 9:45 AM, Richard Biener wrote: > > On Thu, Sep 9, 2021 at 9:37 AM Aldy Hernandez wrote: > >> > >> > >> > >> On 9/9/21 8:57 AM, Richard Biener wrote: > >>> On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote: > > Hell

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/9/21 9:45 AM, Richard Biener wrote: On Thu, Sep 9, 2021 at 9:37 AM Aldy Hernandez wrote: On 9/9/21 8:57 AM, Richard Biener wrote: On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote: Hello, [lame answer to self] On Wed, 8 Sep 2021, Michael Matz wrote: The forward threader guard

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Richard Biener via Gcc
On Thu, Sep 9, 2021 at 10:14 AM Aldy Hernandez wrote: > > > > On 9/8/21 8:13 PM, Michael Matz wrote: > > Hello, > > > > [lame answer to self] > > > > On Wed, 8 Sep 2021, Michael Matz wrote: > > > The forward threader guards against this by simply disallowing > threadings that involve dif

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/8/21 8:13 PM, Michael Matz wrote: Hello, [lame answer to self] On Wed, 8 Sep 2021, Michael Matz wrote: The forward threader guards against this by simply disallowing threadings that involve different loops. As I see The thread in question (5->9->3) is all within the same outer loop

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Richard Biener via Gcc
On Thu, Sep 9, 2021 at 9:37 AM Aldy Hernandez wrote: > > > > On 9/9/21 8:57 AM, Richard Biener wrote: > > On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote: > >> > >> Hello, > >> > >> [lame answer to self] > >> > >> On Wed, 8 Sep 2021, Michael Matz wrote: > >> > > The forward threader guards

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-09 Thread Aldy Hernandez via Gcc
On 9/9/21 8:57 AM, Richard Biener wrote: On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote: Hello, [lame answer to self] On Wed, 8 Sep 2021, Michael Matz wrote: The forward threader guards against this by simply disallowing threadings that involve different loops. As I see The thread

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Richard Biener via Gcc
On Wed, Sep 8, 2021 at 8:13 PM Michael Matz wrote: > > Hello, > > [lame answer to self] > > On Wed, 8 Sep 2021, Michael Matz wrote: > > > > > The forward threader guards against this by simply disallowing > > > > threadings that involve different loops. As I see > > > > > > The thread in question

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Michael Matz via Gcc
Hello, [lame answer to self] On Wed, 8 Sep 2021, Michael Matz wrote: > > > The forward threader guards against this by simply disallowing > > > threadings that involve different loops. As I see > > > > The thread in question (5->9->3) is all within the same outer loop, > > though. BTW, the b

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Michael Matz via Gcc
Hello, On Wed, 8 Sep 2021, Aldy Hernandez wrote: > > The forward threader guards against this by simply disallowing > > threadings that involve different loops. As I see > > The thread in question (5->9->3) is all within the same outer loop, > though. BTW, the backward threader also disallows

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Aldy Hernandez via Gcc
On 9/8/21 3:49 PM, Richard Biener wrote: On Wed, Sep 8, 2021 at 3:25 PM Aldy Hernandez wrote: It would be helpful to have the patch causing the issue to look at the IL. But as Micha said, there needs to be a perfect loop nest for interchange to work. Richard. Absolutely! I'm attaching th

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Richard Biener via Gcc
On Wed, Sep 8, 2021 at 3:25 PM Aldy Hernandez wrote: > > > It would be helpful to have the patch causing the issue to look at the IL. > > But as Micha said, there needs to be a perfect loop nest for interchange > > to work. > > > > Richard. > > Absolutely! I'm attaching the reduced testcase, as w

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Aldy Hernandez via Gcc
It would be helpful to have the patch causing the issue to look at the IL. But as Micha said, there needs to be a perfect loop nest for interchange to work. Richard. Absolutely! I'm attaching the reduced testcase, as well as the patch. The problematic thread shows up in the thread2 dump: Che

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Richard Biener via Gcc
On Wed, Sep 8, 2021 at 12:44 PM Aldy Hernandez wrote: > > First of all. Thanks so much for this incredibly useful explanation. > It helps a lot. > > I'm still trying to wrap my head around this, so please bear with me. > > On 9/7/21 4:45 PM, Michael Matz wrote: > > Hello, > > > > On Tue, 7 Sep 20

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-08 Thread Aldy Hernandez via Gcc
First of all. Thanks so much for this incredibly useful explanation. It helps a lot. I'm still trying to wrap my head around this, so please bear with me. On 9/7/21 4:45 PM, Michael Matz wrote: Hello, On Tue, 7 Sep 2021, Aldy Hernandez via Gcc wrote: The regression comes from the simple_re

Re: More aggressive threading causing loop-interchange-9.c regression

2021-09-07 Thread Michael Matz via Gcc
Hello, On Tue, 7 Sep 2021, Aldy Hernandez via Gcc wrote: > The regression comes from the simple_reduc_1() function in > tree-ssa/loop-interchange-9.c, and it involves the following path: > > === BB 5 > Imports: n_10(D) j_19 > Exports: n_10(D) j_13 j_19 > j_13 : j

More aggressive threading causing loop-interchange-9.c regression

2021-09-07 Thread Aldy Hernandez via Gcc
Hi folks. I have a pending patch for the path solver that pulls in global ranges when available (the stuff in SSA_NAME_RANGE_INFO). In doing so, I have run into a regression I was hoping the loop experts could pontificate on. The regression comes from the simple_reduc_1() function in tree-s