Skip to content

Commit ac62b8f

Browse files
committed
[ConstraintElimination] Update addFact to take Predicate and ops (NFC).
This allows adding facts without necessarily having a corresponding CmpInst.
1 parent 9301054 commit ac62b8f

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ class ConstraintInfo {
142142

143143
bool doesHold(CmpInst::Predicate Pred, Value *A, Value *B) const;
144144

145-
void addFact(CmpInst *Condition, bool IsNegated, unsigned NumIn,
146-
unsigned NumOut, SmallVectorImpl<StackEntry> &DFSInStack);
145+
void addFact(CmpInst::Predicate Pred, Value *A, Value *B, bool IsNegated,
146+
unsigned NumIn, unsigned NumOut,
147+
SmallVectorImpl<StackEntry> &DFSInStack);
147148

148149
/// Turn a comparison of the form \p Op0 \p Pred \p Op1 into a vector of
149150
/// constraints, using indices from the corresponding constraint system.
@@ -526,19 +527,19 @@ void State::addInfoFor(BasicBlock &BB) {
526527
WorkList.emplace_back(DT.getNode(Br->getSuccessor(1)), CmpI, true);
527528
}
528529

529-
void ConstraintInfo::addFact(CmpInst *Condition, bool IsNegated, unsigned NumIn,
530-
unsigned NumOut,
530+
void ConstraintInfo::addFact(CmpInst::Predicate Pred, Value *A, Value *B,
531+
bool IsNegated, unsigned NumIn, unsigned NumOut,
531532
SmallVectorImpl<StackEntry> &DFSInStack) {
532533
// If the constraint has a pre-condition, skip the constraint if it does not
533534
// hold.
534535
DenseMap<Value *, unsigned> NewIndices;
535-
auto R = getConstraint(Condition, NewIndices);
536+
auto R = getConstraint(Pred, A, B, NewIndices);
536537
if (!R.isValid(*this))
537538
return;
538539

539-
LLVM_DEBUG(dbgs() << "Adding " << *Condition << " " << IsNegated << "\n");
540+
//LLVM_DEBUG(dbgs() << "Adding " << *Condition << " " << IsNegated << "\n");
540541
bool Added = false;
541-
assert(CmpInst::isSigned(Condition->getPredicate()) == R.IsSigned &&
542+
assert(CmpInst::isSigned(Pred) == R.IsSigned &&
542543
"condition and constraint signs must match");
543544
auto &CSToUse = getCS(R.IsSigned);
544545
if (R.Coefficients.empty())
@@ -759,9 +760,13 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
759760
}
760761
}
761762

762-
// Otherwise, add the condition to the system and stack, if we can transform
763-
// it into a constraint.
764-
Info.addFact(CB.Condition, CB.Not, CB.NumIn, CB.NumOut, DFSInStack);
763+
ICmpInst::Predicate Pred;
764+
Value *A, *B;
765+
if (match(CB.Condition, m_ICmp(Pred, m_Value(A), m_Value(B)))) {
766+
// Otherwise, add the condition to the system and stack, if we can
767+
// transform it into a constraint.
768+
Info.addFact(Pred, A, B, CB.Not, CB.NumIn, CB.NumOut, DFSInStack);
769+
}
765770
}
766771

767772
#ifndef NDEBUG

0 commit comments

Comments
 (0)