@@ -3612,32 +3612,42 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
3612
3612
}
3613
3613
}
3614
3614
}
3615
- } else if (ISD::isZEXTLoad (Op.getNode ()) && Op.getResNo () == 0 ) {
3616
- // If this is a ZEXTLoad and we are looking at the loaded value.
3617
- EVT VT = LD->getMemoryVT ();
3618
- unsigned MemBits = VT.getScalarSizeInBits ();
3619
- Known.Zero .setBitsFrom (MemBits);
3620
- } else if (const MDNode *Ranges = LD->getRanges ()) {
3621
- EVT VT = LD->getValueType (0 );
3622
-
3623
- // TODO: Handle for extending loads
3624
- if (LD->getExtensionType () == ISD::NON_EXTLOAD) {
3615
+ } else if (Op.getResNo () == 0 ) {
3616
+ KnownBits Known0 (!LD->getMemoryVT ().isScalableVT ()
3617
+ ? LD->getMemoryVT ().getSizeInBits ()
3618
+ : BitWidth);
3619
+ EVT VT = Op.getValueType ();
3620
+ // Fill in any known bits from range information. There are 3 types being
3621
+ // used. The results VT (same vector elt size as BitWidth), the loaded
3622
+ // MemoryVT (which may or may not be vector) and the range VTs original
3623
+ // type. The range matadata needs the full range (i.e
3624
+ // MemoryVT().getSizeInBits()), which is truncated to the correct elt size
3625
+ // if it is know. These are then extended to the original VT sizes below.
3626
+ if (const MDNode *MD = LD->getRanges ()) {
3627
+ computeKnownBitsFromRangeMetadata (*MD, Known0);
3625
3628
if (VT.isVector ()) {
3626
3629
// Handle truncation to the first demanded element.
3627
3630
// TODO: Figure out which demanded elements are covered
3628
3631
if (DemandedElts != 1 || !getDataLayout ().isLittleEndian ())
3629
3632
break ;
3633
+ Known0 = Known0.trunc (BitWidth);
3634
+ }
3635
+ }
3630
3636
3631
- // Handle the case where a load has a vector type, but scalar memory
3632
- // with an attached range.
3633
- EVT MemVT = LD->getMemoryVT ();
3634
- KnownBits KnownFull (MemVT.getSizeInBits ());
3637
+ if (LD->getMemoryVT ().isVector ())
3638
+ Known0 = Known0.trunc (LD->getMemoryVT ().getScalarSizeInBits ());
3635
3639
3636
- computeKnownBitsFromRangeMetadata (*Ranges, KnownFull);
3637
- Known = KnownFull.trunc (BitWidth);
3638
- } else
3639
- computeKnownBitsFromRangeMetadata (*Ranges, Known);
3640
- }
3640
+ // Extend the Known bits from memory to the size of the result.
3641
+ if (ISD::isZEXTLoad (Op.getNode ()))
3642
+ Known = Known0.zext (BitWidth);
3643
+ else if (ISD::isSEXTLoad (Op.getNode ()))
3644
+ Known = Known0.sext (BitWidth);
3645
+ else if (ISD::isEXTLoad (Op.getNode ()))
3646
+ Known = Known0.anyext (BitWidth);
3647
+ else
3648
+ Known = Known0;
3649
+ assert (Known.getBitWidth () == BitWidth);
3650
+ return Known;
3641
3651
}
3642
3652
break ;
3643
3653
}
0 commit comments