llvm / llvm/llvm-project

Inefficient AArch64 frame generation with VLAs

Open
#167,982 7 comments 0 reactions 0 assignees View on GitHub
backend:AArch64 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/9dj5eaxa9 shows a function with a mix of callee-saved registers, fixed size stack objects, and variable size stack objects where Clang's code generation is seemingly worse than GCC's:
* Clang requires two more callee-saved registers.
* `x19` is presumably serving as the base pointer, per https://github.com/llvm/llvm-project/blob/3ff3c4eba5d536a578abef6bf1d8520591b26dc2/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp#L83-L84 There's no overaligned local variables here though, so I'm not sure why the base pointer is needed.
* `x21` seemingly serves no purpose: the stack pointer is copied to it in line 11, and then it's copied back to the stack pointer in line 22, but the copied value is immediately overridden two instructions later (line 24), so it's never used.

Is there potential to improve the frame setup here, or am I just missing something in what Clang is doing?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the AArch64 output from the linked Godbolt example, then inspect llvm/lib/Target/AArch64/AArch64FrameLowering.cpp at the referenced frame-lowering logic. Compare the generated frame setup with the VLA, callee-saved register, and stack-object requirements; done means establishing whether the base pointer or x21 is unnecessary and identifying a validated improvement.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.