[llvm] [CodeGen] Avoid aligning alloca size. (PR #132064)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 20 10:35:08 PDT 2025


================
@@ -114,7 +114,7 @@ define void @f5() {
 ; CHECK-NEXT:    lgr %r11, %r15
 ; CHECK-NEXT:    .cfi_def_cfa_register %r11
 ; CHECK-NEXT:    lgr %r1, %r15
-; CHECK-NEXT:    aghi %r1, -128
+; CHECK-NEXT:    aghi %r1, -124
 ; CHECK-NEXT:    la %r2, 280(%r1)
 ; CHECK-NEXT:    nill %r2, 65408
 ; CHECK-NEXT:    lgr %r15, %r1
----------------
jcogan-nv wrote:

> I'm not convinced that isStackRealignable() is relevant here.

Agreed I think the property I am looking for is something like: whether the target uses the stack pointer as the result of `DYNAMIC_STACKALLOC`.

> But on other targets, like s390x...

Makes sense, thanks for the explanation.

> If this is no longer correct, the documentation needs to be updated...

Agreed I would need to update this documentation and audit existing uses. That may be too much effort for this change.  GlobalISel uses an opcode called `G_DYN_STACKALLOC`. Is that assumed to have the same interface/semantics as `DYNAMIC_STACKALLOC`? I don't see any reference to size alignment in the documentation for `G_DYN_STACKALLOC`, here is what I found:

```
/// Build and insert \p Res = G_DYN_STACKALLOC \p Size, \p Align
///
/// G_DYN_STACKALLOC does a dynamic stack allocation and writes the address of
/// the allocated memory into \p Res.
/// \pre setBasicBlock or setMI must have been called.
/// \pre \p Res must be a generic virtual register with pointer type.
///
/// \return a MachineInstrBuilder for the newly created instruction.
MachineInstrBuilder buildDynStackAlloc(const DstOp &Res, const SrcOp &Size,
```

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


More information about the llvm-commits mailing list