diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-18 21:35:19 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-18 21:35:19 +0000 |
commit | 106f0cdefb02afc3064268dc7a71419b409ed2f3 (patch) | |
tree | 4ad937010aa8295e2c74b569946e7fa75b496f58 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 930341ba3066fdac4040b13f3404f8e02eae7afb (diff) | |
download | bcm5719-llvm-106f0cdefb02afc3064268dc7a71419b409ed2f3.tar.gz bcm5719-llvm-106f0cdefb02afc3064268dc7a71419b409ed2f3.zip |
[ValueTracking][InstSimplify] Support min/max selects in computeConstantRange()
Add support for min/max flavor selects in computeConstantRange(),
which allows us to fold comparisons of a min/max against a constant
in InstSimplify. This was suggested by spatel as an alternative
approach to D59378. I've also added the infinite looping test from
that revision here.
Differential Revision: https://reviews.llvm.org/D59506
llvm-svn: 356415
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 00123788f2f..2988043c2a2 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -5680,7 +5680,28 @@ static void setLimitsForSelectPattern(const SelectInst &SI, APInt &Lower, return; } - // TODO Handle min/max flavors. + const APInt *C; + if (!match(LHS, m_APInt(C)) && !match(RHS, m_APInt(C))) + return; + + switch (R.Flavor) { + case SPF_UMIN: + Upper = *C + 1; + break; + case SPF_UMAX: + Lower = *C; + break; + case SPF_SMIN: + Lower = APInt::getSignedMinValue(BitWidth); + Upper = *C + 1; + break; + case SPF_SMAX: + Lower = *C; + Upper = APInt::getSignedMaxValue(BitWidth) + 1; + break; + default: + break; + } } ConstantRange llvm::computeConstantRange(const Value *V, bool UseInstrInfo) { |