Skip to content

Commit 7d274aa

Browse files
committed
[SCEV] Add support for x != 0 to CollectCondition.
Add support for NE predicates with 0 constants. Those can be translated to UMaxExpr(x, 1).
1 parent 3a69ebf commit 7d274aa

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12622,6 +12622,12 @@ const SCEV *ScalarEvolution::applyLoopGuards(const SCEV *Expr, const Loop *L) {
1262212622
if (isa<SCEVConstant>(RHS))
1262312623
RewriteMap[LHSUnknown->getValue()] = RHS;
1262412624
break;
12625+
case CmpInst::ICMP_NE:
12626+
if (isa<SCEVConstant>(RHS) &&
12627+
cast<SCEVConstant>(RHS)->getValue()->isNullValue())
12628+
RewriteMap[LHSUnknown->getValue()] =
12629+
getUMaxExpr(LHS, getOne(RHS->getType()));
12630+
break;
1262512631
default:
1262612632
break;
1262712633
}

llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ exit:
249249
define void @test_guard_ult_ne(i32* nocapture readonly %data, i64 %count) {
250250
; CHECK-LABEL: @test_guard_ult_ne
251251
; CHECK: Loop %loop: backedge-taken count is (-1 + %count)
252-
; CHECK-NEXT: Loop %loop: max backedge-taken count is -2
252+
; CHECK-NEXT: Loop %loop: max backedge-taken count is 3
253253
; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %count)
254254
;
255255
entry:

0 commit comments

Comments
 (0)