[PATCH] Fix SCEVExpander creating distinct duplicate PHI entries

Andrew Trick atrick at apple.com
Fri Aug 16 16:41:50 PDT 2013


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.

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

-Andy



More information about the llvm-commits mailing list