[llvm] [WIP][SPARC] Allow overaligned `alloca`s (PR #107223)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 15 16:09:55 PDT 2024
================
@@ -2811,12 +2818,17 @@ 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
+ AlignedPtr = DAG.getNode(ISD::SUB, dl, VT, AlignedPtr, Size);
----------------
koachan wrote:
A little question here: why is the aligning formula `(ptr - align) & -align` instead of just `ptr & -align`?
In my understanding the latter should avoid excessive allocation too; using your example of `old sp = 40, size = 8, align = 16`:
```
ptr = 40 - 8 // 32
// using (ptr - align) & -align
new sp = (32 - 16) & (-16) // 16, overallocating by 16 bytes
// using ptr & -align
new sp = 32 & -16 // 32
```
https://github.com/llvm/llvm-project/pull/107223
More information about the llvm-commits
mailing list