Skip to content

Commit d51a036

Browse files
committed
!fixup always emit precondition, don't check unique predecessor
1 parent 474acb5 commit d51a036

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,25 +1032,18 @@ void State::addInfoForInductions(BasicBlock &BB) {
10321032
DTN, CmpInst::ICMP_SLT, PN, B,
10331033
ConditionTy(CmpInst::ICMP_SLE, StartValue, B)));
10341034

1035+
// Try to add condition from header to the exit blocks. When exiting either
1036+
// with EQ or NE in the header, we know that the induction value must be u<=
1037+
// B, as other exits may only exit earlier.
10351038
assert(!StepOffset.isNegative() && "induction must be increasing");
1036-
// Try to add condition from header to the unique exit block, if there is one.
1037-
// When exiting either with EQ or NE, we know that the induction value must be
1038-
// u<= B, as a different exit may exit earlier.
1039-
ConditionTy Precond;
1040-
if (!MonotonicallyIncreasingUnsigned)
1041-
Precond = {CmpInst::ICMP_ULE, StartValue, B};
1042-
if (Pred == CmpInst::ICMP_EQ) {
1043-
BasicBlock *EB = cast<BranchInst>(BB.getTerminator())->getSuccessor(0);
1044-
if (L->getUniqueExitBlock() == EB) {
1045-
WorkList.emplace_back(FactOrCheck::getConditionFact(
1046-
DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
1047-
}
1048-
}
1049-
if (Pred == CmpInst::ICMP_NE) {
1050-
BasicBlock *EB = cast<BranchInst>(BB.getTerminator())->getSuccessor(1);
1051-
if (L->getUniqueExitBlock() == EB)
1052-
WorkList.emplace_back(FactOrCheck::getConditionFact(
1053-
DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
1039+
assert((Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE) &&
1040+
"unsupported predicate");
1041+
ConditionTy Precond = {CmpInst::ICMP_ULE, StartValue, B};
1042+
SmallVector<BasicBlock *> ExitBBs;
1043+
L->getExitBlocks(ExitBBs);
1044+
for (BasicBlock *EB : ExitBBs) {
1045+
WorkList.emplace_back(FactOrCheck::getConditionFact(
1046+
DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
10541047
}
10551048
}
10561049

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ define i1 @multi_exiting_loop_eq_different_exits_2_const_compare_known(ptr %s, i
541541
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
542542
; CHECK-NEXT: br i1 [[LATCH_C]], label %[[LOOP_HEADER]], label %[[EXIT_2]]
543543
; CHECK: [[EXIT_1]]:
544-
; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[IV]], 1235
545-
; CHECK-NEXT: ret i1 [[T_1]]
544+
; CHECK-NEXT: ret i1 true
546545
; CHECK: [[EXIT_2]]:
547546
; CHECK-NEXT: ret i1 true
548547
;

0 commit comments

Comments
 (0)