diff options
author | Sanjay Patel <spatel@rotateright.com> | 2022-07-24 17:05:40 -0400 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2022-07-24 17:46:48 -0400 |
commit | a925bef70c6c2a78f1efc4e880d24460ff784003 (patch) | |
tree | bda187cd9e919b8c11ef8439eff36ffb86c25cdd /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 4da47bee48a57cc5fa0256623dbd749c3bf14759 (diff) | |
download | llvm-a925bef70c6c2a78f1efc4e880d24460ff784003.zip llvm-a925bef70c6c2a78f1efc4e880d24460ff784003.tar.gz llvm-a925bef70c6c2a78f1efc4e880d24460ff784003.tar.bz2 |
[ValueTracking] allow vector types in isImpliedCondition()
The matching of constants assumed integers, but we can handle
splat vector constants seamlessly with m_APInt.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 1f3798d..14f4bd6 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.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) |