Skip to content

Commit 941c75a

Browse files
committed
[ValueTracking] Return ConstantRange instead of setting limits (NFC)
Same as previously done for intrinsics.
1 parent 6dc7717 commit 941c75a

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

llvm/lib/Analysis/ValueTracking.cpp

+27-37
Original file line numberDiff line numberDiff line change
@@ -8758,56 +8758,50 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) {
87588758
return ConstantRange::getFull(Width);
87598759
}
87608760

8761-
static void setLimitsForSelectPattern(const SelectInst &SI, APInt &Lower,
8762-
APInt &Upper, const InstrInfoQuery &IIQ) {
8761+
static ConstantRange getRangeForSelectPattern(const SelectInst &SI,
8762+
const InstrInfoQuery &IIQ) {
8763+
unsigned BitWidth = SI.getType()->getScalarSizeInBits();
87638764
const Value *LHS = nullptr, *RHS = nullptr;
87648765
SelectPatternResult R = matchSelectPattern(&SI, LHS, RHS);
87658766
if (R.Flavor == SPF_UNKNOWN)
8766-
return;
8767-
8768-
unsigned BitWidth = SI.getType()->getScalarSizeInBits();
8767+
return ConstantRange::getFull(BitWidth);
87698768

87708769
if (R.Flavor == SelectPatternFlavor::SPF_ABS) {
87718770
// If the negation part of the abs (in RHS) has the NSW flag,
87728771
// then the result of abs(X) is [0..SIGNED_MAX],
87738772
// otherwise it is [0..SIGNED_MIN], as -SIGNED_MIN == SIGNED_MIN.
8774-
Lower = APInt::getZero(BitWidth);
87758773
if (match(RHS, m_Neg(m_Specific(LHS))) &&
87768774
IIQ.hasNoSignedWrap(cast<Instruction>(RHS)))
8777-
Upper = APInt::getSignedMaxValue(BitWidth) + 1;
8778-
else
8779-
Upper = APInt::getSignedMinValue(BitWidth) + 1;
8780-
return;
8775+
return ConstantRange::getNonEmpty(APInt::getZero(BitWidth),
8776+
APInt::getSignedMaxValue(BitWidth) + 1);
8777+
8778+
return ConstantRange::getNonEmpty(APInt::getZero(BitWidth),
8779+
APInt::getSignedMinValue(BitWidth) + 1);
87818780
}
87828781

87838782
if (R.Flavor == SelectPatternFlavor::SPF_NABS) {
87848783
// The result of -abs(X) is <= 0.
8785-
Lower = APInt::getSignedMinValue(BitWidth);
8786-
Upper = APInt(BitWidth, 1);
8787-
return;
8784+
return ConstantRange::getNonEmpty(APInt::getSignedMinValue(BitWidth),
8785+
APInt(BitWidth, 1));
87888786
}
87898787

87908788
const APInt *C;
87918789
if (!match(LHS, m_APInt(C)) && !match(RHS, m_APInt(C)))
8792-
return;
8790+
return ConstantRange::getFull(BitWidth);
87938791

87948792
switch (R.Flavor) {
8795-
case SPF_UMIN:
8796-
Upper = *C + 1;
8797-
break;
8798-
case SPF_UMAX:
8799-
Lower = *C;
8800-
break;
8801-
case SPF_SMIN:
8802-
Lower = APInt::getSignedMinValue(BitWidth);
8803-
Upper = *C + 1;
8804-
break;
8805-
case SPF_SMAX:
8806-
Lower = *C;
8807-
Upper = APInt::getSignedMaxValue(BitWidth) + 1;
8808-
break;
8809-
default:
8810-
break;
8793+
case SPF_UMIN:
8794+
return ConstantRange::getNonEmpty(APInt::getZero(BitWidth), *C + 1);
8795+
case SPF_UMAX:
8796+
return ConstantRange::getNonEmpty(*C, APInt::getZero(BitWidth));
8797+
case SPF_SMIN:
8798+
return ConstantRange::getNonEmpty(APInt::getSignedMinValue(BitWidth),
8799+
*C + 1);
8800+
case SPF_SMAX:
8801+
return ConstantRange::getNonEmpty(*C,
8802+
APInt::getSignedMaxValue(BitWidth) + 1);
8803+
default:
8804+
return ConstantRange::getFull(BitWidth);
88118805
}
88128806
}
88138807

@@ -8853,13 +8847,9 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
88538847
CR = ConstantRange::getNonEmpty(Lower, Upper);
88548848
} else if (auto *II = dyn_cast<IntrinsicInst>(V))
88558849
CR = getRangeForIntrinsic(*II);
8856-
else if (auto *SI = dyn_cast<SelectInst>(V)) {
8857-
APInt Lower = APInt(BitWidth, 0);
8858-
APInt Upper = APInt(BitWidth, 0);
8859-
// TODO: Return ConstantRange.
8860-
setLimitsForSelectPattern(*SI, Lower, Upper, IIQ);
8861-
CR = ConstantRange::getNonEmpty(Lower, Upper);
8862-
} else if (isa<FPToUIInst>(V) || isa<FPToSIInst>(V)) {
8850+
else if (auto *SI = dyn_cast<SelectInst>(V))
8851+
CR = getRangeForSelectPattern(*SI, IIQ);
8852+
else if (isa<FPToUIInst>(V) || isa<FPToSIInst>(V)) {
88638853
APInt Lower = APInt(BitWidth, 0);
88648854
APInt Upper = APInt(BitWidth, 0);
88658855
// TODO: Return ConstantRange.

0 commit comments

Comments
 (0)