[llvm] [SelectionDAG] Use unaligned store to move AVX registers onto stack for `extractelement` (PR #78422)

Manish Kausik H via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 22:19:58 PST 2024


================
@@ -1377,6 +1378,20 @@ void SelectionDAGLegalize::LegalizeOp(SDNode *Node) {
   }
 }
 
+// Helper function that generates an MMO that considers the alignment of the
+// stack, and the size of the stack object
+static MachineMemOperand *getStackAlignedMMO(SDValue StackPtr,
+                                             MachineFunction &MF) {
+  auto &MFI = MF.getFrameInfo();
+  int FI = cast<FrameIndexSDNode>(StackPtr)->getIndex();
+  MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI);
+  MachineMemOperand *MMO =
+      MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore,
+                              MFI.getObjectSize(FI), MFI.getObjectAlign(FI));
----------------
Nirhar wrote:

@davemgreen do we have some representation for Unknown size? 

Here is what I propose to change this function to:
```
static MachineMemOperand *getStackAlignedMMO(SDValue StackPtr,
                                             MachineFunction &MF, bool isScalableObject) {
  auto &MFI = MF.getFrameInfo();
  int FI = cast<FrameIndexSDNode>(StackPtr)->getIndex();
  MachinePointerInfo PtrInfo = MachinePointerInfo::getFixedStack(MF, FI);
  auto objectSize = isScalableObject ? UNKNOWN_SIZE : MFI.getObjectSize();
  MachineMemOperand *MMO =
      MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOStore,
                              objectSize, MFI.getObjectAlign(FI));
  return MMO;
}
```
but I do not know if this is feasible in the current framework. 

I also considered passing an `LLT`as argument to `MF.getMachineMemOperand` which is initialized with `LLT::scalable_vector`, however I was unsure of what to pass as arguments to this function in this case. Can you help me out?

https://github.com/llvm/llvm-project/pull/78422


More information about the llvm-commits mailing list