[LLVMdev] -indvars issues?

Tobias Grosser tobias at grosser.es
Thu Mar 8 15:23:09 PST 2012


On 03/08/2012 06:23 PM, Gavin Harrison wrote:
> Hi,
>
> Is the -indvars pass functional? I've done some small test to check it,
> but this fails to canonicalize:
>
>> int *x;
>> int *y;
>> int i;
>> ...
>> for (i = 1; i < 100; i+=2) {
>> x[i] = y[i] + 3;
>> }
>
> The IR produced after -indvars:
>
>> br label %for.cond
>>
>> for.cond: ; preds = %for.inc, %entry
>> %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 1, %entry ]
>> %0 = trunc i64 %indvars.iv to i32
>> %cmp = icmp slt i32 %0, 100
>> br i1 %cmp, label %for.body, label %for.end
>>
>> for.body: ; preds = %for.cond
>> %arrayidx = getelementptr inbounds i32* %y, i64 %indvars.iv
>> %1 = load i32* %arrayidx, align 4
>> %add = add nsw i32 %1, 3
>> %arrayidx2 = getelementptr inbounds i32* %x, i64 %indvars.iv
>> store i32 %add, i32* %arrayidx2, align 4
>> br label %for.inc
>>
>> for.inc: ; preds = %for.body
>> %indvars.iv.next = add i64 %indvars.iv, 2
>> br label %for.cond
>>
>> for.end: ; preds = %for.cond
>
> Which isn't in canonical form. Is there some trick to getting this pass
> to work? I've tried adding various other passes ahead of it, like
> -aa-eval, -scalar-evolution, -mem2reg, -lcssa, -loop-simplify, etc but
> to no avail.

-indvars does not canonicalize as much any more, as more passes can 
handle non canonical loops. To get the old canonicalization add 
-enable-iv-rewrite on the command line. Though I would not rely on this, 
as this flag is about to be removed.

Cheers
Tobi



More information about the llvm-dev mailing list