aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@codeaurora.org>2016-05-05 15:39:18 +0000
committerChad Rosier <mcrosier@codeaurora.org>2016-05-05 15:39:18 +0000
commit25cfb7dbd640391f6f55dd6423aa82258209e45f (patch)
tree116d13f7de312aa1b6e2ee729abe77c3a78f5fbf /llvm/lib/Analysis/ValueTracking.cpp
parente57662d5ec3a50e77fc35d8e25d7442cb3af6474 (diff)
downloadllvm-25cfb7dbd640391f6f55dd6423aa82258209e45f.zip
llvm-25cfb7dbd640391f6f55dd6423aa82258209e45f.tar.gz
llvm-25cfb7dbd640391f6f55dd6423aa82258209e45f.tar.bz2
[ValueTracking] Improve isImpliedCondition for matching LHS and Imm RHSs.
llvm-svn: 268636
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index aca7608..fa5c491 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3948,6 +3948,27 @@ static Optional<bool> isImpliedCondMatchingOperands(CmpInst::Predicate APred,
return None;
}
+/// Return true if "icmp1 APred ALHS C1" implies "icmp2 BPred BLHS C2" is
+/// true. Return false if "icmp1 APred ALHS C1" implies "icmp2 BPred BLHS
+/// C2" is false. Otherwise, return None if we can't infer anything.
+static Optional<bool>
+isImpliedCondMatchingImmOperands(CmpInst::Predicate APred, Value *ALHS,
+ ConstantInt *C1, CmpInst::Predicate BPred,
+ Value *BLHS, ConstantInt *C2) {
+ assert(ALHS == BLHS && "LHS operands must match.");
+ ConstantRange DomCR =
+ ConstantRange::makeExactICmpRegion(APred, C1->getValue());
+ ConstantRange CR =
+ ConstantRange::makeAllowedICmpRegion(BPred, C2->getValue());
+ ConstantRange Intersection = DomCR.intersectWith(CR);
+ ConstantRange Difference = DomCR.difference(CR);
+ if (Intersection.isEmptySet())
+ return false;
+ if (Difference.isEmptySet())
+ return true;
+ return None;
+}
+
Optional<bool> llvm::isImpliedCondition(Value *LHS, Value *RHS,
const DataLayout &DL, bool InvertAPred,
unsigned Depth, AssumptionCache *AC,
@@ -3985,6 +4006,14 @@ Optional<bool> llvm::isImpliedCondition(Value *LHS, Value *RHS,
if (Implication)
return Implication;
+ if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
+ Implication =
+ isImpliedCondMatchingImmOperands(APred, ALHS, cast<ConstantInt>(ARHS),
+ BPred, BLHS, cast<ConstantInt>(BRHS));
+ if (Implication)
+ return Implication;
+ }
+
if (APred == BPred)
return isImpliedCondOperands(APred, ALHS, ARHS, BLHS, BRHS, DL, Depth, AC,
CxtI, DT);