Skip to content

Commit ff5519f

Browse files
committed
!fixup properly handle non-monotonically increasing case.
1 parent 45a6a87 commit ff5519f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,17 +1036,21 @@ void State::addInfoForInductions(BasicBlock &BB) {
10361036
// Try to add condition from header to the unique exit block, if there is one.
10371037
// When exiting either with EQ or NE, we know that the induction value must be
10381038
// u<= B, as a different exit may exit earlier.
1039+
ConditionTy Precond;
1040+
if (!MonotonicallyIncreasingUnsigned)
1041+
Precond = {CmpInst::ICMP_ULE, StartValue, B};
10391042
if (Pred == CmpInst::ICMP_EQ) {
10401043
BasicBlock *EB = cast<BranchInst>(BB.getTerminator())->getSuccessor(0);
1041-
if (L->getUniqueExitBlock() == EB)
1044+
if (L->getUniqueExitBlock() == EB) {
10421045
WorkList.emplace_back(FactOrCheck::getConditionFact(
1043-
DT.getNode(EB), CmpInst::ICMP_ULE, A, B));
1046+
DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
1047+
}
10441048
}
10451049
if (Pred == CmpInst::ICMP_NE) {
10461050
BasicBlock *EB = cast<BranchInst>(BB.getTerminator())->getSuccessor(1);
10471051
if (L->getUniqueExitBlock() == EB)
10481052
WorkList.emplace_back(FactOrCheck::getConditionFact(
1049-
DT.getNode(EB), CmpInst::ICMP_ULE, A, B));
1053+
DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
10501054
}
10511055
}
10521056

llvm/test/Transforms/ConstraintElimination/induction-condition-in-loop-exit.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ define i1 @multi_exiting_loop_eq_same_unique_exit_const_compare_known_due_to_pre
9898
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
9999
; CHECK-NEXT: br i1 [[LATCH_C]], label %[[LOOP_HEADER]], label %[[EXIT]]
100100
; CHECK: [[EXIT]]:
101-
; CHECK-NEXT: [[T:%.*]] = icmp ult i32 [[IV]], 1235
102-
; CHECK-NEXT: ret i1 [[T]]
101+
; CHECK-NEXT: ret i1 true
103102
;
104103
entry:
105104
%pre.c = icmp ule i32 %start, 1234

0 commit comments

Comments
 (0)