[ValueTracking] allow vector types in isImpliedCondition()
The matching of constants assumed integers, but we can handle splat vector constants seamlessly with m_APInt.
This commit is contained in:
parent
4da47bee48
commit
a925bef70c
|
@ -6543,7 +6543,6 @@ bool llvm::matchSimpleRecurrence(const BinaryOperator *I, PHINode *&P,
|
|||
static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS,
|
||||
const Value *RHS, const DataLayout &DL,
|
||||
unsigned Depth) {
|
||||
assert(!LHS->getType()->isVectorTy() && "TODO: extend to handle vectors!");
|
||||
if (ICmpInst::isTrueWhenEqual(Pred) && LHS == RHS)
|
||||
return true;
|
||||
|
||||
|
@ -6656,14 +6655,12 @@ static Optional<bool> isImpliedCondMatchingOperands(CmpInst::Predicate APred,
|
|||
/// Return true if "icmp APred X, C1" implies "icmp BPred X, C2" is true.
|
||||
/// Return false if "icmp APred X, C1" implies "icmp BPred X, C2" is false.
|
||||
/// Otherwise, return None if we can't infer anything.
|
||||
static Optional<bool>
|
||||
isImpliedCondMatchingImmOperands(CmpInst::Predicate APred,
|
||||
const ConstantInt *C1,
|
||||
CmpInst::Predicate BPred,
|
||||
const ConstantInt *C2) {
|
||||
ConstantRange DomCR =
|
||||
ConstantRange::makeExactICmpRegion(APred, C1->getValue());
|
||||
ConstantRange CR = ConstantRange::makeExactICmpRegion(BPred, C2->getValue());
|
||||
static Optional<bool> isImpliedCondMatchingImmOperands(CmpInst::Predicate APred,
|
||||
const APInt &C1,
|
||||
CmpInst::Predicate BPred,
|
||||
const APInt &C2) {
|
||||
ConstantRange DomCR = ConstantRange::makeExactICmpRegion(APred, C1);
|
||||
ConstantRange CR = ConstantRange::makeExactICmpRegion(BPred, C2);
|
||||
ConstantRange Intersection = DomCR.intersectWith(CR);
|
||||
ConstantRange Difference = DomCR.difference(CR);
|
||||
if (Intersection.isEmptySet())
|
||||
|
@ -6701,14 +6698,9 @@ static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
|
|||
|
||||
// Can we infer anything when the LHS operands match and the RHS operands are
|
||||
// constants (not necessarily matching)?
|
||||
if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
|
||||
if (Optional<bool> Implication = isImpliedCondMatchingImmOperands(
|
||||
APred, cast<ConstantInt>(ARHS), BPred, cast<ConstantInt>(BRHS)))
|
||||
return Implication;
|
||||
// No amount of additional analysis will infer the second condition, so
|
||||
// early exit.
|
||||
return None;
|
||||
}
|
||||
const APInt *AC, *BC;
|
||||
if (ALHS == BLHS && match(ARHS, m_APInt(AC)) && match(BRHS, m_APInt(BC)))
|
||||
return isImpliedCondMatchingImmOperands(APred, *AC, BPred, *BC);
|
||||
|
||||
if (APred == BPred)
|
||||
return isImpliedCondOperands(APred, ALHS, ARHS, BLHS, BRHS, DL, Depth);
|
||||
|
@ -6764,12 +6756,6 @@ llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred,
|
|||
Type *OpTy = LHS->getType();
|
||||
assert(OpTy->isIntOrIntVectorTy(1) && "Expected integer type only!");
|
||||
|
||||
// FIXME: Extending the code below to handle vectors.
|
||||
if (OpTy->isVectorTy())
|
||||
return None;
|
||||
|
||||
assert(OpTy->isIntegerTy(1) && "implied by above");
|
||||
|
||||
// Both LHS and RHS are icmps.
|
||||
const ICmpInst *LHSCmp = dyn_cast<ICmpInst>(LHS);
|
||||
if (LHSCmp)
|
||||
|
|
|
@ -1354,7 +1354,7 @@ TEST_F(ValueTrackingTest, IsImpliedConditionAndVec) {
|
|||
}
|
||||
)");
|
||||
const DataLayout &DL = M->getDataLayout();
|
||||
EXPECT_EQ(isImpliedCondition(A, A2, DL), None);
|
||||
EXPECT_EQ(isImpliedCondition(A, A2, DL), true);
|
||||
}
|
||||
|
||||
TEST_F(ValueTrackingTest, IsImpliedConditionOr) {
|
||||
|
|
Loading…
Reference in a new issue