summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2016-03-09 21:31:47 +0000
committerPhilip Reames <listmail@philipreames.com>2016-03-09 21:31:47 +0000
commit8f12eba78d7ef7cd849af8e6658e6a20c6f6f772 (patch)
tree394453df7083c9113b4d4b1676f6a209e24008cb /llvm/lib
parent2b4df612ecb3503cb849231f96e2b90f8db546fe (diff)
downloadbcm5719-llvm-8f12eba78d7ef7cd849af8e6658e6a20c6f6f772.tar.gz
bcm5719-llvm-8f12eba78d7ef7cd849af8e6658e6a20c6f6f772.zip
[ValueTracking] Extract isKnownPositive [NFCI]
Extract out a generic interface from a recently landed patch and document a TODO in case compile time becomes a problem. llvm-svn: 263062
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp12
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp4
2 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 098da0afca5..79529e5fa79 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -182,6 +182,18 @@ bool llvm::isKnownNonNegative(Value *V, const DataLayout &DL, unsigned Depth,
return NonNegative;
}
+bool llvm::isKnownPositive(Value *V, const DataLayout &DL, unsigned Depth,
+ AssumptionCache *AC, const Instruction *CxtI,
+ const DominatorTree *DT) {
+ if (auto *CI = dyn_cast<ConstantInt>(V))
+ return CI->getValue().isStrictlyPositive();
+
+ // TODO: We'd doing two recursive queries here. We should factor this such
+ // that only a single query is needed.
+ return isKnownNonNegative(V, DL, Depth, AC, CxtI, DT) &&
+ isKnownNonZero(V, DL, Depth, AC, CxtI, DT);
+}
+
static bool isKnownNonEqual(Value *V1, Value *V2, const Query &Q);
bool llvm::isKnownNonEqual(Value *V1, Value *V2, const DataLayout &DL,
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 703506d8098..7401cb6034a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3178,9 +3178,9 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (auto *SI = dyn_cast<SelectInst>(Op0)) {
SelectPatternResult SPR = matchSelectPattern(SI, A, B);
if (SPR.Flavor == SPF_SMIN) {
- if (isKnownNonNegative(A, DL) && isKnownNonZero(A, DL))
+ if (isKnownPositive(A, DL))
return new ICmpInst(I.getPredicate(), B, CI);
- if (isKnownNonNegative(B, DL) && isKnownNonZero(B, DL))
+ if (isKnownPositive(B, DL))
return new ICmpInst(I.getPredicate(), A, CI);
}
}
OpenPOWER on IntegriCloud