|
21 | 21 | #include "llvm/Analysis/ConstantFolding.h"
|
22 | 22 | #include "llvm/Analysis/TargetLibraryInfo.h"
|
23 | 23 | #include "llvm/CodeGen/ISDOpcodes.h"
|
| 24 | +#include "llvm/CodeGen/MachineFrameInfo.h" |
24 | 25 | #include "llvm/CodeGen/MachineFunction.h"
|
25 | 26 | #include "llvm/CodeGen/MachineJumpTableInfo.h"
|
26 | 27 | #include "llvm/CodeGen/MachineMemOperand.h"
|
@@ -1377,6 +1378,21 @@ void SelectionDAGLegalize::LegalizeOp(SDNode *Node) {
|
1377 | 1378 | }
|
1378 | 1379 | }
|
1379 | 1380 |
|
| 1381 | +// Helper function that generates an MMO that considers the alignment of the |
| 1382 | +// stack, and the size of the stack object |
| 1383 | +static MachineMemOperand *getStackAlignedMMO(SDValue StackPtr, |
| 1384 | + MachineFunction &MF, |
| 1385 | + bool isObjectScalable) { |
| 1386 | + auto &MFI = MF.getFrameInfo(); |
| 1387 | + int FI = cast<FrameIndexSDNode>(StackPtr)->getIndex(); |
| 1388 | + MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI); |
| 1389 | + uint64_t ObjectSize = isObjectScalable ? ~UINT64_C(0) : MFI.getObjectSize(FI); |
| 1390 | + MachineMemOperand *MMO = MF.getMachineMemOperand( |
| 1391 | + PtrInfo, MachineMemOperand::MOStore, ObjectSize, MFI.getObjectAlign(FI)); |
| 1392 | + |
| 1393 | + return MMO; |
| 1394 | +} |
| 1395 | + |
1380 | 1396 | SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(SDValue Op) {
|
1381 | 1397 | SDValue Vec = Op.getOperand(0);
|
1382 | 1398 | SDValue Idx = Op.getOperand(1);
|
@@ -1426,8 +1442,9 @@ SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(SDValue Op) {
|
1426 | 1442 | if (!Ch.getNode()) {
|
1427 | 1443 | // Store the value to a temporary stack slot, then LOAD the returned part.
|
1428 | 1444 | StackPtr = DAG.CreateStackTemporary(VecVT);
|
1429 |
| - Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, |
1430 |
| - MachinePointerInfo()); |
| 1445 | + MachineMemOperand *StoreMMO = getStackAlignedMMO( |
| 1446 | + StackPtr, DAG.getMachineFunction(), VecVT.isScalableVector()); |
| 1447 | + Ch = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, StoreMMO); |
1431 | 1448 | }
|
1432 | 1449 |
|
1433 | 1450 | SDValue NewLoad;
|
|
0 commit comments