[PATCH] Fix SCEVExpander creating distinct duplicate PHI entries

Hal Finkel hfinkel at anl.gov
Sat Aug 17 17:30:14 PDT 2013


----- Original Message -----
> 
> On Aug 16, 2013, at 11:27 AM, Hal Finkel <hfinkel at anl.gov> wrote:
> 
> > Andy, et al.,
> > 
> > Please review this (small) patch which fixes SCEVExpander so that
> > it does not create multiple distinct induction variables for
> > duplicate PHI entries. Specifically, given some code like this:
> > 
> > do.body6:                                         ; preds =
> > %do.body6, %do.body6, %if.then5
> >  %end.0 = phi i8* [ undef, %if.then5 ], [ %incdec.ptr, %do.body6 ],
> >  [ %incdec.ptr, %do.body6 ]
> > ...
> > 
> > (and it is apparently legal to have multiple entries for a basic
> > block so long as the associated value is the same)
> > 
> > Expanding an AddRec in this loop can produce code like this:
> > 
> > do.body6:                                         ; preds =
> > %do.body6, %do.body6, %if.then5
> >  %indvar = phi i64 [ %indvar.next, %do.body6 ], [ %indvar.next1,
> >  %do.body6 ], [ 0, %if.then5 ]
> >  %end.0 = phi i8* [ undef, %if.then5 ], [ %incdec.ptr, %do.body6 ],
> >  [ %incdec.ptr, %do.body6 ]
> > ...
> >  %indvar.next = add i64 %indvar, 1
> >  %indvar.next1 = add i64 %indvar, 1
> > 
> > Unfortunately, I don't have an in-tree test case.
> 
> LGTM.

r188614. Thanks!

> 
> FYI: replaceCongruentPhis should be able to clean these up. But I
> don’t see the harm in avoiding them in the first place.

Interesting, I see that LSR and IndVarSimplify call SCEVExpander::replaceCongruentIVs. I think that the problem I was having is that the code hitting this problem was running prior to LSR.

 -Hal

> 
> -Andy

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory




More information about the llvm-commits mailing list