[llvm] [WIP][SPARC] Allow overaligned `alloca`s (PR #107223)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 05:10:53 PDT 2024


================
@@ -2764,20 +2764,27 @@ static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
                                        const SparcSubtarget *Subtarget) {
   SDValue Chain = Op.getOperand(0);  // Legalize the chain.
   SDValue Size  = Op.getOperand(1);  // Legalize the size.
-  MaybeAlign Alignment =
-      cast<ConstantSDNode>(Op.getOperand(2))->getMaybeAlignValue();
+  SDValue Alignment = Op.getOperand(2); // Legalize the alignment.
+  MaybeAlign MaybeAlignment =
+      cast<ConstantSDNode>(Alignment)->getMaybeAlignValue();
   Align StackAlign = Subtarget->getFrameLowering()->getStackAlign();
   EVT VT = Size->getValueType(0);
   SDLoc dl(Op);
 
-  // TODO: implement over-aligned alloca. (Note: also implies
-  // supporting support for overaligned function frames + dynamic
-  // allocations, at all, which currently isn't supported)
-  if (Alignment && *Alignment > StackAlign) {
-    const MachineFunction &MF = DAG.getMachineFunction();
-    report_fatal_error("Function \"" + Twine(MF.getName()) + "\": "
-                       "over-aligned dynamic alloca not supported.");
-  }
+  int64_t Bias = Subtarget->getStackPointerBias();
+  unsigned SPReg = SP::O6;
+  SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
+  SDValue AlignedPtr = SP;
+
+  bool IsOveraligned = MaybeAlignment && *MaybeAlignment > StackAlign;
----------------
s-barannikov wrote:

There is no need for the second check.
Alignment, if present, is guaranteed to be greater than the stack alignment.


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


More information about the llvm-commits mailing list