This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] simplify more icmps with pred sle/ule to pred slt/ult
AbandonedPublic

Authored by shchenz on Jul 24 2019, 11:42 PM.

Details

Summary
define void @sle(i8* %p, i32 %a, i32 %b) {
...
for.body: 
%i.04 = phi i32 [ %a, %for.body.lr.ph ], [ %inc, %for.body ]
%inc = add nsw i32 %i.04, 1
%cmp = icmp sle i32 %inc, %b
br i1 %cmp, label %for.body, label %for.end
...
}

SCEV for %i.04 is {%a, +, 1}, SCEV for icmp LHS(%inc) is {(%a + 1) <nsw>, + , 1}. Currently, the range for LHS is full-set.

In patch https://reviews.llvm.org/D64869, the range for LHS is corrected to [INT32_MIN+1, INT32_MIN).

This patch is based on the fixed range in https://reviews.llvm.org/D64869 to get backedge-taken for more loops. We can convert more sle/ule to slt/ult.

Diff Detail

Event Timeline

shchenz created this revision.Jul 24 2019, 11:42 PM
shchenz edited the summary of this revision. (Show Details)Jul 25 2019, 1:39 AM
shchenz planned changes to this revision.Oct 7 2019, 6:52 PM

https://reviews.llvm.org/D64868 is reverted, need to fix that firstly.

shchenz abandoned this revision.Dec 23 2019, 12:34 AM

Right solution should be https://reviews.llvm.org/D71690. We can convert sle to slt if get(Signed|Unsigned)RangeMin(LHS) is not min value. In https://reviews.llvm.org/D71690, we can get a more accurate min value for AddRec with flag nsw|nuw.