@@ -14912,21 +14912,29 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
1491214912 if (ShAmt == 0 && OldRanges) {
1491314913 Type *NewTy = VT.getTypeForEVT(*DAG.getContext());
1491414914 const unsigned NumOperands = OldRanges->getNumOperands();
14915+ unsigned NumRanges = NumOperands / 2;
1491514916 const unsigned NewWidth = NewTy->getIntegerBitWidth();
1491614917 bool InRange = true;
1491714918 SmallVector<Metadata *, 4> Bounds;
1491814919 Bounds.reserve(NumOperands);
1491914920
14920- for (unsigned i = 0; i < NumOperands; ++i) {
14921- const APInt &BoundValue =
14922- mdconst::extract<ConstantInt>(OldRanges->getOperand(i))->getValue();
14923- if (BoundValue.getBitWidth() - BoundValue.getNumSignBits() >=
14924- NewWidth) {
14921+ for (unsigned i = 0; i < NumRanges; ++i) {
14922+ const APInt &LowValue =
14923+ mdconst::extract<ConstantInt>(OldRanges->getOperand(2 * i))
14924+ ->getValue();
14925+ const APInt &HighValue =
14926+ mdconst::extract<ConstantInt>(OldRanges->getOperand(2 * i + 1))
14927+ ->getValue();
14928+ ConstantRange CurRange(LowValue, HighValue);
14929+
14930+ if (CurRange.getMinSignedBits() > NewWidth) {
1492514931 InRange = false;
1492614932 break;
1492714933 }
1492814934 Bounds.push_back(ConstantAsMetadata::get(
14929- ConstantInt::get(NewTy, BoundValue.trunc(NewWidth))));
14935+ ConstantInt::get(NewTy, LowValue.trunc(NewWidth))));
14936+ Bounds.push_back(ConstantAsMetadata::get(
14937+ ConstantInt::get(NewTy, HighValue.trunc(NewWidth))));
1493014938 }
1493114939 if (InRange)
1493214940 NewRanges = MDNode::get(*DAG.getContext(), Bounds);
0 commit comments