[LLVMdev] [PATCH] Teaching ScalarEvolution to handle IV=add(zext(trunc(IV)), Step)

Dan Gohman dan433584 at gmail.com
Fri Dec 21 10:26:07 PST 2012


On Thu, Dec 20, 2012 at 8:36 AM, Matthew Curtis <mcurtis at codeaurora.org> wrote:
> Ok, so I think I've mis-represented what's really happening.
> Ignore my previous statements concerning %add :)
>
> Again, given:
>
> 05:  for.body:                                         ; preds = %entry,
> %for.body
> 06:    %j.04 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
> 07:    %result.03 = phi i32 [ 0, %entry ], [ %add, %for.body ]
> 08:    %conv2 = and i32 %result.03, 255
> 09:    %add = add nsw i32 %conv2, 3
> 10:    %inc = add nsw i32 %j.04, 1
> 11:    %cmp = icmp slt i32 %inc, 8000
> 12:    br i1 %cmp, label %for.body, label %for.end
>
> LLVM executes the following:
>
> 01:  createSCEV(%conv2 = and i32 %result.03, 255)
> 02:    calls getSCEV(%result.03)
> 03:       returns (3 + (zext i8 {-3,+,3}<%for.body> to i32))

The problem is that this is not a correct expression for %result.03.
It isn't safe to use incorrect expressions in ScalarEvolution even if
it happens to work out in the case you're looking at.

Dan



More information about the llvm-dev mailing list