[PATCH] D25738: [IndVarSimplify] Use control-dependent range information to prove non-negativity

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 11:07:58 PDT 2016


apilipenko created this revision.
apilipenko added reviewers: sanjoy, reames, lihuang.
apilipenko added a subscriber: llvm-commits.

This change is motivated by the case when IndVarSimplify doesn't widen a comparison of IV increment because it can't prove IV increment being non-negative. We end up with a redundant trunc of the widened increment on this example.

  for.body:
    %i = phi i32 [ %start, %for.body.lr.ph ], [ %i.inc, %for.inc ]
    %within_limits = icmp ult i32 %i, 64
    br i1 %within_limits, label %continue, label %for.end
  
  continue:
    %i.i64 = zext i32 %i to i64
    %arrayidx = getelementptr inbounds i32, i32* %base, i64 %i.i64
    %val = load i32, i32* %arrayidx, align 4
    br label %for.inc
  
  for.inc:
    %i.inc = add nsw nuw i32 %i, 1
    %cmp = icmp slt i32 %i.inc, %limit
    br i1 %cmp, label %for.body, label %for.end

There is a range check inside of the loop which guarantees the IV to be non-negative. NSW on the increment guarantees that the increment is also non-negative. ScalarEvolution can't prove that the increments non-negative because it doesn't reason about control dependencies inside of the loop. Teach IndVarSimplify to use the range check to prove non-negativity of loop increments.

      

It's difficult to gather control-dependent information on demand, because when it's needed some of the dominating conditions might be already widened. That's why collect control-dependent ranges before any transformation occurs for all increments of the IV and all uses of these increments.


https://reviews.llvm.org/D25738

Files:
  lib/Transforms/Scalar/IndVarSimplify.cpp
  test/Transforms/IndVarSimplify/post-inc-range.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25738.75031.patch
Type: text/x-patch
Size: 9485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161018/4cbc237d/attachment.bin>


More information about the llvm-commits mailing list