Skip to content

Commit 00fbc32

Browse files
committed
[SCEV] Better preserve wrapping info in SimplifyICmpOperands for UGE.
1 parent 2578122 commit 00fbc32

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10892,7 +10892,8 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS,
1089210892
}
1089310893
break;
1089410894
case ICmpInst::ICMP_UGE:
10895-
if (!getUnsignedRangeMin(RHS).isMinValue()) {
10895+
// If we can fold -1 into RHS, try that first.
10896+
if ((isa<SCEVConstant>(RHS) || match(RHS, m_scev_AffineAddRec(m_SCEVConstant(), m_SCEV(), m_Loop()))) && !getUnsignedRangeMin(RHS).isMinValue()) {
1089610897
RHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), RHS);
1089710898
Pred = ICmpInst::ICMP_UGT;
1089810899
Changed = true;
@@ -10901,6 +10902,10 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS,
1090110902
SCEV::FlagNUW);
1090210903
Pred = ICmpInst::ICMP_UGT;
1090310904
Changed = true;
10905+
} else if (!getUnsignedRangeMin(RHS).isMinValue()) {
10906+
RHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), RHS);
10907+
Pred = ICmpInst::ICMP_UGT;
10908+
Changed = true;
1090410909
}
1090510910
break;
1090610911
default:

llvm/test/Transforms/IndVarSimplify/simplify-icmp-operands-order.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ loop.latch:
5353

5454
define void @test_simplifycompare_rhs_not_constant1() {
5555
; CHECK-LABEL: define void @test_simplifycompare_rhs_not_constant1() {
56-
; CHECK-NEXT: [[ENTRY:.*]]:
56+
; CHECK-NEXT: [[ENTRY:.*:]]
5757
; CHECK-NEXT: [[P:%.*]] = alloca i64, align 8
5858
; CHECK-NEXT: br label %[[LOOP:.*]]
5959
; CHECK: [[LOOP]]:
60-
; CHECK-NEXT: [[PTR_IV:%.*]] = phi ptr [ [[P]], %[[ENTRY]] ], [ [[PTR_IV_NEXT:%.*]], %[[LOOP]] ]
61-
; CHECK-NEXT: [[PTR_IV_NEXT]] = getelementptr i8, ptr [[PTR_IV]], i64 -8
62-
; CHECK-NEXT: call void @use(ptr [[PTR_IV]])
63-
; CHECK-NEXT: [[EC:%.*]] = icmp ult ptr [[PTR_IV_NEXT]], [[P]]
64-
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]
60+
; CHECK-NEXT: call void @use(ptr [[P]])
61+
; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[LOOP]]
6562
; CHECK: [[EXIT]]:
6663
; CHECK-NEXT: ret void
6764
;

0 commit comments

Comments
 (0)