Skip to content

Commit a90be3a

Browse files
committed
[ConstraintElim] Fix miscompilation
1 parent d5a8743 commit a90be3a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,9 +1498,6 @@ static bool checkOrAndOpImpliedByOther(
14981498
FactOrCheck &CB, ConstraintInfo &Info, Module *ReproducerModule,
14991499
SmallVectorImpl<ReproducerEntry> &ReproducerCondStack,
15001500
SmallVectorImpl<StackEntry> &DFSInStack) {
1501-
1502-
CmpInst::Predicate Pred;
1503-
Value *A, *B;
15041501
Instruction *JoinOp = CB.getContextInst();
15051502
CmpInst *CmpToCheck = cast<CmpInst>(CB.getInstructionToSimplify());
15061503
unsigned OtherOpIdx = JoinOp->getOperand(0) == CmpToCheck ? 1 : 0;
@@ -1513,6 +1510,14 @@ static bool checkOrAndOpImpliedByOther(
15131510

15141511
// Optimistically add fact from first condition.
15151512
unsigned OldSize = DFSInStack.size();
1513+
auto InfoRestorer = make_scope_exit([&]() {
1514+
// Remove entries again.
1515+
while (OldSize < DFSInStack.size()) {
1516+
StackEntry E = DFSInStack.back();
1517+
removeEntryFromStack(E, Info, ReproducerModule, ReproducerCondStack,
1518+
DFSInStack);
1519+
}
1520+
});
15161521
// For OR, check if the negated condition implies CmpToCheck.
15171522
bool IsOr = match(JoinOp, m_LogicalOr());
15181523
SmallVector<Value *, 4> Worklist({JoinOp->getOperand(OtherOpIdx)});
@@ -1537,7 +1542,6 @@ static bool checkOrAndOpImpliedByOther(
15371542
if (OldSize == DFSInStack.size())
15381543
return false;
15391544

1540-
bool Changed = false;
15411545
// Check if the second condition can be simplified now.
15421546
if (auto ImpliedCondition =
15431547
checkCondition(CmpToCheck->getPredicate(), CmpToCheck->getOperand(0),
@@ -1551,16 +1555,10 @@ static bool checkOrAndOpImpliedByOther(
15511555
1 - OtherOpIdx,
15521556
ConstantInt::getBool(JoinOp->getType(), *ImpliedCondition));
15531557

1554-
Changed = true;
1558+
return true;
15551559
}
15561560

1557-
// Remove entries again.
1558-
while (OldSize < DFSInStack.size()) {
1559-
StackEntry E = DFSInStack.back();
1560-
removeEntryFromStack(E, Info, ReproducerModule, ReproducerCondStack,
1561-
DFSInStack);
1562-
}
1563-
return Changed;
1561+
return false;
15641562
}
15651563

15661564
void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,

0 commit comments

Comments
 (0)