@@ -14961,14 +14961,14 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
1496114961 const MDNode *OldRanges = LN0->getRanges();
1496214962 const MDNode *NewRanges = nullptr;
1496314963 // If LSBs are loaded and the truncated ConstantRange for the OldRanges
14964- // metadata is not the full-set for the NewWidth then create a NewRanges
14964+ // metadata is not the full-set for the new width then create a NewRanges
1496514965 // metadata for the truncated load
1496614966 if (ShAmt == 0 && OldRanges) {
1496714967 ConstantRange CR = getConstantRangeFromMetadata(*OldRanges);
1496814968
14969- // FIXME: OldRanges should match the width of the old load, so
14970- // CR.getBitWidth() should be wider than the new narrower load. This
14971- // check should be unnecessary .
14969+ // It is possible for an 8-bit extending load with 8-bit range
14970+ // metadata to be narrowed to an 8-bit load. This guard is necessary to
14971+ // ensure that truncation is strictly smaller .
1497214972 if (CR.getBitWidth() > VT.getScalarSizeInBits()) {
1497314973 ConstantRange TruncatedCR = CR.truncate(VT.getScalarSizeInBits());
1497414974 if (!TruncatedCR.isFullSet()) {
@@ -14979,7 +14979,8 @@ SDValue DAGCombiner::reduceLoadWidth(SDNode *N) {
1497914979 ConstantInt::get(*DAG.getContext(), TruncatedCR.getUpper()))};
1498014980 NewRanges = MDNode::get(*DAG.getContext(), Bounds);
1498114981 }
14982- }
14982+ } else if (CR.getBitWidth() == VT.getScalarSizeInBits())
14983+ NewRanges = OldRanges;
1498314984 }
1498414985 Load = DAG.getLoad(
1498514986 VT, DL, LN0->getChain(), NewPtr,
0 commit comments