[LLVMdev] -indvars issues?

Gavin Harrison gavin.har at gmail.com
Thu Mar 8 09:23:34 PST 2012


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.

Thank you,
Gavin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120308/0aaeb898/attachment.html>


More information about the llvm-dev mailing list