|
24 | 24 | #include "llvm/Analysis/MemoryLocation.h"
|
25 | 25 | #include "llvm/Analysis/VectorUtils.h"
|
26 | 26 | #include "llvm/CodeGen/ISDOpcodes.h"
|
| 27 | +#include "llvm/CodeGen/MachineFrameInfo.h" |
27 | 28 | #include "llvm/IR/DataLayout.h"
|
28 | 29 | #include "llvm/Support/ErrorHandling.h"
|
29 | 30 | #include "llvm/Support/TypeSize.h"
|
@@ -221,6 +222,22 @@ void DAGTypeLegalizer::ScalarizeVectorResult(SDNode *N, unsigned ResNo) {
|
221 | 222 | SetScalarizedVector(SDValue(N, ResNo), R);
|
222 | 223 | }
|
223 | 224 |
|
| 225 | +// Helper function that generates an MMO that considers the alignment of the |
| 226 | +// stack, and the size of the stack object |
| 227 | +// Note: A copy of this function exists in LegalizeDAG.cpp |
| 228 | +static MachineMemOperand *getStackAlignedMMO(SDValue StackPtr, |
| 229 | + MachineFunction &MF, |
| 230 | + bool isObjectScalable) { |
| 231 | + auto &MFI = MF.getFrameInfo(); |
| 232 | + int FI = cast<FrameIndexSDNode>(StackPtr)->getIndex(); |
| 233 | + MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI); |
| 234 | + LocationSize ObjectSize = isObjectScalable |
| 235 | + ? LocationSize::beforeOrAfterPointer() |
| 236 | + : LocationSize::precise(MFI.getObjectSize(FI)); |
| 237 | + return MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore, |
| 238 | + ObjectSize, MFI.getObjectAlign(FI)); |
| 239 | +} |
| 240 | + |
224 | 241 | SDValue DAGTypeLegalizer::ScalarizeVecRes_BinOp(SDNode *N) {
|
225 | 242 | SDValue LHS = GetScalarizedVector(N->getOperand(0));
|
226 | 243 | SDValue RHS = GetScalarizedVector(N->getOperand(1));
|
@@ -3531,14 +3548,14 @@ SDValue DAGTypeLegalizer::SplitVecOp_EXTRACT_VECTOR_ELT(SDNode *N) {
|
3531 | 3548 | // Store the vector to the stack.
|
3532 | 3549 | // In cases where the vector is illegal it will be broken down into parts
|
3533 | 3550 | // and stored in parts - we should use the alignment for the smallest part.
|
3534 |
| - Align SmallestAlign = DAG.getReducedAlign(VecVT, /*UseABI=*/false); |
| 3551 | + Align SmallestAlign = |
| 3552 | + std::min(DAG.getSubtarget().getFrameLowering()->getStackAlign(), |
| 3553 | + DAG.getReducedAlign(VecVT, /*UseABI=*/false)); |
3535 | 3554 | SDValue StackPtr =
|
3536 | 3555 | DAG.CreateStackTemporary(VecVT.getStoreSize(), SmallestAlign);
|
3537 |
| - auto &MF = DAG.getMachineFunction(); |
3538 |
| - auto FrameIndex = cast<FrameIndexSDNode>(StackPtr.getNode())->getIndex(); |
3539 |
| - auto PtrInfo = MachinePointerInfo::getFixedStack(MF, FrameIndex); |
3540 |
| - SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, PtrInfo, |
3541 |
| - SmallestAlign); |
| 3556 | + MachineMemOperand *StoreMMO = getStackAlignedMMO( |
| 3557 | + StackPtr, DAG.getMachineFunction(), VecVT.isScalableVector()); |
| 3558 | + SDValue Store = DAG.getStore(DAG.getEntryNode(), dl, Vec, StackPtr, StoreMMO); |
3542 | 3559 |
|
3543 | 3560 | // Load back the required element.
|
3544 | 3561 | StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT, Idx);
|
|
0 commit comments