@@ -8758,56 +8758,50 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) {
8758
8758
return ConstantRange::getFull (Width);
8759
8759
}
8760
8760
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 ();
8763
8764
const Value *LHS = nullptr , *RHS = nullptr ;
8764
8765
SelectPatternResult R = matchSelectPattern (&SI, LHS, RHS);
8765
8766
if (R.Flavor == SPF_UNKNOWN)
8766
- return ;
8767
-
8768
- unsigned BitWidth = SI.getType ()->getScalarSizeInBits ();
8767
+ return ConstantRange::getFull (BitWidth);
8769
8768
8770
8769
if (R.Flavor == SelectPatternFlavor::SPF_ABS) {
8771
8770
// If the negation part of the abs (in RHS) has the NSW flag,
8772
8771
// then the result of abs(X) is [0..SIGNED_MAX],
8773
8772
// otherwise it is [0..SIGNED_MIN], as -SIGNED_MIN == SIGNED_MIN.
8774
- Lower = APInt::getZero (BitWidth);
8775
8773
if (match (RHS, m_Neg (m_Specific (LHS))) &&
8776
8774
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 );
8781
8780
}
8782
8781
8783
8782
if (R.Flavor == SelectPatternFlavor::SPF_NABS) {
8784
8783
// 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 ));
8788
8786
}
8789
8787
8790
8788
const APInt *C;
8791
8789
if (!match (LHS, m_APInt (C)) && !match (RHS, m_APInt (C)))
8792
- return ;
8790
+ return ConstantRange::getFull (BitWidth) ;
8793
8791
8794
8792
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);
8811
8805
}
8812
8806
}
8813
8807
@@ -8853,13 +8847,9 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
8853
8847
CR = ConstantRange::getNonEmpty (Lower, Upper);
8854
8848
} else if (auto *II = dyn_cast<IntrinsicInst>(V))
8855
8849
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)) {
8863
8853
APInt Lower = APInt (BitWidth, 0 );
8864
8854
APInt Upper = APInt (BitWidth, 0 );
8865
8855
// TODO: Return ConstantRange.
0 commit comments