[compiler-rt] [llvm] [SPARC] Allow overaligned `alloca`s (PR #107223)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 26 16:46:42 PDT 2024
================
@@ -2811,16 +2805,30 @@ static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG,
regSpillArea = 96;
}
- unsigned SPReg = SP::O6;
- SDValue SP = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
- SDValue NewSP = DAG.getNode(ISD::SUB, dl, VT, SP, Size); // Value
- Chain = DAG.getCopyToReg(SP.getValue(1), dl, SPReg, NewSP); // Output chain
-
- regSpillArea += Subtarget->getStackPointerBias();
-
- SDValue NewVal = DAG.getNode(ISD::ADD, dl, VT, NewSP,
- DAG.getConstant(regSpillArea, dl, VT));
- SDValue Ops[2] = { NewVal, Chain };
+ int64_t Bias = Subtarget->getStackPointerBias();
+
+ // Debias and increment SP past the reserved spill area.
+ // We need the SP to point to the first usable region before calculating
+ // anything to prevent any of the pointers from becoming out of alignment when
+ // we rebias the SP later on.
+ SDValue StartOfUsableStack = DAG.getNode(
+ ISD::ADD, dl, VT, SP, DAG.getConstant(regSpillArea + Bias, dl, VT));
+ SDValue AllocatedPtr =
+ DAG.getNode(ISD::SUB, dl, VT, StartOfUsableStack, Size);
+
+ bool IsOveraligned = MaybeAlignment.has_value();
+ SDValue AlignedPtr =
+ IsOveraligned
+ ? DAG.getNode(ISD::AND, dl, VT, AllocatedPtr,
+ DAG.getNode(ISD::SUB, dl, VT,
+ DAG.getConstant(0, dl, VT), Alignment))
----------------
s-barannikov wrote:
```suggestion
DAG.getConstant(-*MaybeAlignment, dl, VT))
```
https://github.com/llvm/llvm-project/pull/107223
More information about the llvm-commits
mailing list