[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,
|
static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS,
|
||||||
const Value *RHS, const DataLayout &DL,
|
const Value *RHS, const DataLayout &DL,
|
||||||
unsigned Depth) {
|
unsigned Depth) {
|
||||||
assert(!LHS->getType()->isVectorTy() && "TODO: extend to handle vectors!");
|
|
||||||
if (ICmpInst::isTrueWhenEqual(Pred) && LHS == RHS)
|
if (ICmpInst::isTrueWhenEqual(Pred) && LHS == RHS)
|
||||||
return true;
|
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 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.
|
/// Return false if "icmp APred X, C1" implies "icmp BPred X, C2" is false.
|
||||||
/// Otherwise, return None if we can't infer anything.
|
/// Otherwise, return None if we can't infer anything.
|
||||||
static Optional<bool>
|
static Optional<bool> isImpliedCondMatchingImmOperands(CmpInst::Predicate APred,
|
||||||
isImpliedCondMatchingImmOperands(CmpInst::Predicate APred,
|
const APInt &C1,
|
||||||
const ConstantInt *C1,
|
CmpInst::Predicate BPred,
|
||||||
CmpInst::Predicate BPred,
|
const APInt &C2) {
|
||||||
const ConstantInt *C2) {
|
ConstantRange DomCR = ConstantRange::makeExactICmpRegion(APred, C1);
|
||||||
ConstantRange DomCR =
|
ConstantRange CR = ConstantRange::makeExactICmpRegion(BPred, C2);
|
||||||
ConstantRange::makeExactICmpRegion(APred, C1->getValue());
|
|
||||||
ConstantRange CR = ConstantRange::makeExactICmpRegion(BPred, C2->getValue());
|
|
||||||
ConstantRange Intersection = DomCR.intersectWith(CR);
|
ConstantRange Intersection = DomCR.intersectWith(CR);
|
||||||
ConstantRange Difference = DomCR.difference(CR);
|
ConstantRange Difference = DomCR.difference(CR);
|
||||||
if (Intersection.isEmptySet())
|
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
|
// Can we infer anything when the LHS operands match and the RHS operands are
|
||||||
// constants (not necessarily matching)?
|
// constants (not necessarily matching)?
|
||||||
if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
|
const APInt *AC, *BC;
|
||||||
if (Optional<bool> Implication = isImpliedCondMatchingImmOperands(
|
if (ALHS == BLHS && match(ARHS, m_APInt(AC)) && match(BRHS, m_APInt(BC)))
|
||||||
APred, cast<ConstantInt>(ARHS), BPred, cast<ConstantInt>(BRHS)))
|
return isImpliedCondMatchingImmOperands(APred, *AC, BPred, *BC);
|
||||||
return Implication;
|
|
||||||
// No amount of additional analysis will infer the second condition, so
|
|
||||||
// early exit.
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (APred == BPred)
|
if (APred == BPred)
|
||||||
return isImpliedCondOperands(APred, ALHS, ARHS, BLHS, BRHS, DL, Depth);
|
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();
|
Type *OpTy = LHS->getType();
|
||||||
assert(OpTy->isIntOrIntVectorTy(1) && "Expected integer type only!");
|
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.
|
// Both LHS and RHS are icmps.
|
||||||
const ICmpInst *LHSCmp = dyn_cast<ICmpInst>(LHS);
|
const ICmpInst *LHSCmp = dyn_cast<ICmpInst>(LHS);
|
||||||
if (LHSCmp)
|
if (LHSCmp)
|
||||||
|
|
|
@ -1354,7 +1354,7 @@ TEST_F(ValueTrackingTest, IsImpliedConditionAndVec) {
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
const DataLayout &DL = M->getDataLayout();
|
const DataLayout &DL = M->getDataLayout();
|
||||||
EXPECT_EQ(isImpliedCondition(A, A2, DL), None);
|
EXPECT_EQ(isImpliedCondition(A, A2, DL), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ValueTrackingTest, IsImpliedConditionOr) {
|
TEST_F(ValueTrackingTest, IsImpliedConditionOr) {
|
||||||
|
|
Loading…
Reference in a new issue