diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 1fc2ed4fc70e0..9a574fa1eb24b 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -141,6 +141,8 @@ class ConstraintInfo { getCS(Signed).popLastNVariables(N); } + bool doesHold(CmpInst::Predicate Pred, Value *A, Value *B) const; + void addFact(CmpInst *Condition, bool IsNegated, unsigned NumIn, unsigned NumOut, SmallVectorImpl &DFSInStack); @@ -364,16 +366,24 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1, bool ConstraintTy::isValid(const ConstraintInfo &Info) const { return Coefficients.size() > 0 && all_of(Preconditions, [&Info](const PreconditionTy &C) { - DenseMap NewIndices; - auto R = Info.getConstraint(C.Pred, C.Op0, C.Op1, NewIndices); - // TODO: properly check NewIndices. - return NewIndices.empty() && R.Preconditions.empty() && !R.IsEq && - R.size() >= 1 && - Info.getCS(CmpInst::isSigned(C.Pred)) - .isConditionImplied(R.Coefficients); + return Info.doesHold(C.Pred, C.Op0, C.Op1); }); } +bool ConstraintInfo::doesHold(CmpInst::Predicate Pred, Value *A, + Value *B) const { + DenseMap NewIndices; + auto R = getConstraint(Pred, A, B, NewIndices); + + if (!NewIndices.empty()) + return false; + + // TODO: properly check NewIndices. + return NewIndices.empty() && R.Preconditions.empty() && !R.IsEq && + !R.empty() && + getCS(CmpInst::isSigned(Pred)).isConditionImplied(R.Coefficients); +} + namespace { /// Represents either a condition that holds on entry to a block or a basic /// block, with their respective Dominator DFS in and out numbers.