@@ -4726,8 +4726,6 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
4726
4726
// for the narrowed load.
4727
4727
for (unsigned width = 8 ; width < origWidth; width *= 2 ) {
4728
4728
EVT newVT = EVT::getIntegerVT (*DAG.getContext (), width);
4729
- if (!shouldReduceLoadWidth (Lod, ISD::NON_EXTLOAD, newVT))
4730
- continue ;
4731
4729
APInt newMask = APInt::getLowBitsSet (maskWidth, width);
4732
4730
// Avoid accessing any padding here for now (we could use memWidth
4733
4731
// instead of origWidth here otherwise).
@@ -4737,8 +4735,11 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
4737
4735
unsigned ptrOffset =
4738
4736
Layout.isLittleEndian () ? offset : memWidth - width - offset;
4739
4737
unsigned IsFast = 0 ;
4738
+ assert ((ptrOffset % 8 ) == 0 && " Non-Bytealigned pointer offset" );
4740
4739
Align NewAlign = commonAlignment (Lod->getAlign (), ptrOffset / 8 );
4741
- if (allowsMemoryAccess (
4740
+ if (shouldReduceLoadWidth (Lod, ISD::NON_EXTLOAD, newVT,
4741
+ ptrOffset / 8 ) &&
4742
+ allowsMemoryAccess (
4742
4743
*DAG.getContext (), Layout, newVT, Lod->getAddressSpace (),
4743
4744
NewAlign, Lod->getMemOperand ()->getFlags (), &IsFast) &&
4744
4745
IsFast) {
@@ -12176,24 +12177,27 @@ SDValue TargetLowering::scalarizeExtractedVectorLoad(EVT ResultVT,
12176
12177
12177
12178
ISD::LoadExtType ExtTy =
12178
12179
ResultVT.bitsGT (VecEltVT) ? ISD::EXTLOAD : ISD::NON_EXTLOAD;
12179
- if (!isOperationLegalOrCustom (ISD::LOAD, VecEltVT) ||
12180
- !shouldReduceLoadWidth (OriginalLoad, ExtTy, VecEltVT))
12180
+ if (!isOperationLegalOrCustom (ISD::LOAD, VecEltVT))
12181
12181
return SDValue ();
12182
12182
12183
+ std::optional<unsigned > ByteOffset;
12183
12184
Align Alignment = OriginalLoad->getAlign ();
12184
12185
MachinePointerInfo MPI;
12185
12186
if (auto *ConstEltNo = dyn_cast<ConstantSDNode>(EltNo)) {
12186
12187
int Elt = ConstEltNo->getZExtValue ();
12187
- unsigned PtrOff = VecEltVT.getSizeInBits () * Elt / 8 ;
12188
- MPI = OriginalLoad->getPointerInfo ().getWithOffset (PtrOff );
12189
- Alignment = commonAlignment (Alignment, PtrOff );
12188
+ ByteOffset = VecEltVT.getSizeInBits () * Elt / 8 ;
12189
+ MPI = OriginalLoad->getPointerInfo ().getWithOffset (*ByteOffset );
12190
+ Alignment = commonAlignment (Alignment, *ByteOffset );
12190
12191
} else {
12191
12192
// Discard the pointer info except the address space because the memory
12192
12193
// operand can't represent this new access since the offset is variable.
12193
12194
MPI = MachinePointerInfo (OriginalLoad->getPointerInfo ().getAddrSpace ());
12194
12195
Alignment = commonAlignment (Alignment, VecEltVT.getSizeInBits () / 8 );
12195
12196
}
12196
12197
12198
+ if (!shouldReduceLoadWidth (OriginalLoad, ExtTy, VecEltVT, ByteOffset))
12199
+ return SDValue ();
12200
+
12197
12201
unsigned IsFast = 0 ;
12198
12202
if (!allowsMemoryAccess (*DAG.getContext (), DAG.getDataLayout (), VecEltVT,
12199
12203
OriginalLoad->getAddressSpace (), Alignment,
0 commit comments