[llvm] r263062 - [ValueTracking] Extract isKnownPositive [NFCI]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 9 13:31:47 PST 2016
Author: reames
Date: Wed Mar 9 15:31:47 2016
New Revision: 263062
URL: http://llvm.org/viewvc/llvm-project?rev=263062&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/Analysis/ValueTracking.h
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=263062&r1=263061&r2=263062&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Wed Mar 9 15:31:47 2016
@@ -92,6 +92,13 @@ namespace llvm {
const Instruction *CxtI = nullptr,
const DominatorTree *DT = nullptr);
+ /// Returns true if the given value is known be positive (i.e. non-negative
+ /// and non-zero).
+ bool isKnownPositive(Value *V, const DataLayout &DL, unsigned Depth = 0,
+ AssumptionCache *AC = nullptr,
+ const Instruction *CxtI = nullptr,
+ const DominatorTree *DT = nullptr);
+
/// isKnownNonEqual - Return true if the given values are known to be
/// non-equal when defined. Supports scalar integer types only.
bool isKnownNonEqual(Value *V1, Value *V2, const DataLayout &DL,
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=263062&r1=263061&r2=263062&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Wed Mar 9 15:31:47 2016
@@ -182,6 +182,18 @@ bool llvm::isKnownNonNegative(Value *V,
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,
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=263062&r1=263061&r2=263062&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Mar 9 15:31:47 2016
@@ -3178,9 +3178,9 @@ Instruction *InstCombiner::visitICmpInst
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);
}
}
More information about the llvm-commits
mailing list