[llvm] a925bef - [ValueTracking] allow vector types in isImpliedCondition()
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 24 14:47:48 PDT 2022
Author: Sanjay Patel
Date: 2022-07-24T17:46:48-04:00
New Revision: a925bef70c6c2a78f1efc4e880d24460ff784003
URL: https://github.com/llvm/llvm-project/commit/a925bef70c6c2a78f1efc4e880d24460ff784003
DIFF: https://github.com/llvm/llvm-project/commit/a925bef70c6c2a78f1efc4e880d24460ff784003.diff
LOG: [ValueTracking] allow vector types in isImpliedCondition()
The matching of constants assumed integers, but we can handle
splat vector constants seamlessly with m_APInt.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 1f3798d1338e7..14f4bd6a6b555 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -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.
diff erence(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)
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index e8b90907f4134..902107d30082c 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -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) {
More information about the llvm-commits
mailing list