diff options
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 64 |
1 files changed, 27 insertions, 37 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 0736ef6..eb9747d 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8758,56 +8758,50 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) { return ConstantRange::getFull(Width); } -static void setLimitsForSelectPattern(const SelectInst &SI, APInt &Lower, - APInt &Upper, const InstrInfoQuery &IIQ) { +static ConstantRange getRangeForSelectPattern(const SelectInst &SI, + const InstrInfoQuery &IIQ) { + unsigned BitWidth = SI.getType()->getScalarSizeInBits(); const Value *LHS = nullptr, *RHS = nullptr; SelectPatternResult R = matchSelectPattern(&SI, LHS, RHS); if (R.Flavor == SPF_UNKNOWN) - return; - - unsigned BitWidth = SI.getType()->getScalarSizeInBits(); + return ConstantRange::getFull(BitWidth); if (R.Flavor == SelectPatternFlavor::SPF_ABS) { // If the negation part of the abs (in RHS) has the NSW flag, // then the result of abs(X) is [0..SIGNED_MAX], // otherwise it is [0..SIGNED_MIN], as -SIGNED_MIN == SIGNED_MIN. - Lower = APInt::getZero(BitWidth); if (match(RHS, m_Neg(m_Specific(LHS))) && IIQ.hasNoSignedWrap(cast<Instruction>(RHS))) - Upper = APInt::getSignedMaxValue(BitWidth) + 1; - else - Upper = APInt::getSignedMinValue(BitWidth) + 1; - return; + return ConstantRange::getNonEmpty(APInt::getZero(BitWidth), + APInt::getSignedMaxValue(BitWidth) + 1); + + return ConstantRange::getNonEmpty(APInt::getZero(BitWidth), + APInt::getSignedMinValue(BitWidth) + 1); } if (R.Flavor == SelectPatternFlavor::SPF_NABS) { // The result of -abs(X) is <= 0. - Lower = APInt::getSignedMinValue(BitWidth); - Upper = APInt(BitWidth, 1); - return; + return ConstantRange::getNonEmpty(APInt::getSignedMinValue(BitWidth), + APInt(BitWidth, 1)); } const APInt *C; if (!match(LHS, m_APInt(C)) && !match(RHS, m_APInt(C))) - return; + return ConstantRange::getFull(BitWidth); 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; + case SPF_UMIN: + return ConstantRange::getNonEmpty(APInt::getZero(BitWidth), *C + 1); + case SPF_UMAX: + return ConstantRange::getNonEmpty(*C, APInt::getZero(BitWidth)); + case SPF_SMIN: + return ConstantRange::getNonEmpty(APInt::getSignedMinValue(BitWidth), + *C + 1); + case SPF_SMAX: + return ConstantRange::getNonEmpty(*C, + APInt::getSignedMaxValue(BitWidth) + 1); + default: + return ConstantRange::getFull(BitWidth); } } @@ -8853,13 +8847,9 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned, CR = ConstantRange::getNonEmpty(Lower, Upper); } else if (auto *II = dyn_cast<IntrinsicInst>(V)) CR = getRangeForIntrinsic(*II); - else if (auto *SI = dyn_cast<SelectInst>(V)) { - APInt Lower = APInt(BitWidth, 0); - APInt Upper = APInt(BitWidth, 0); - // TODO: Return ConstantRange. - setLimitsForSelectPattern(*SI, Lower, Upper, IIQ); - CR = ConstantRange::getNonEmpty(Lower, Upper); - } else if (isa<FPToUIInst>(V) || isa<FPToSIInst>(V)) { + else if (auto *SI = dyn_cast<SelectInst>(V)) + CR = getRangeForSelectPattern(*SI, IIQ); + else if (isa<FPToUIInst>(V) || isa<FPToSIInst>(V)) { APInt Lower = APInt(BitWidth, 0); APInt Upper = APInt(BitWidth, 0); // TODO: Return ConstantRange. |