[llvm] [AArch64][MachineOutliner] Allow calls to be outlined when PAC is enabled (PR #230840)
Mazen Hatem via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 11 12:34:05 PDT 2026
================
@@ -10587,6 +10587,11 @@ AArch64InstrInfo::getOutliningCandidateInfo(
int SPValue = 0;
for (auto &MI : C) {
if (MI.modifiesRegister(AArch64::SP, &TRI)) {
+ // Calls implicitly modify the stack, but they are already vetted by
+ // getOutliningTypeImpl to only be outlined as safe tail-calls.
+ if (MI.isCall())
----------------
MazenEwiss wrote:
Great question! It comes down to a collision between how LLVM models calls in Machine IR and how PAC-RET signs the return address.
1. **Calls implicitly modify `SP`**: In LLVM MIR, call instructions (like `BL` or `BLR`) are modeled with an implicit `Def` of `SP` to represent the ABI call boundary. Because of this, `MI.modifiesRegister(AArch64::SP, &TRI)` mathematically returns `true` for all calls.
2. **PAC requires strict `SP` validation**: When pointer authentication is enabled, the outliner must guarantee that `SP` is identical at the point of authentication because PAC-RET thunks use `pacibsp` / `autibsp` (which use the current `SP` value as the cryptographic modifier). To enforce this, the outliner runs the `hasIllegalSPModification` check.
3. **The collision**: When PAC is enabled, `hasIllegalSPModification` scans the candidate, sees the implicit `SP` definition on the call instruction, and conservatively rejects it because it isn't a balanced `ADD`/`SUB` pair. When PAC is disabled, this strict `SP` verification is skipped entirely, so the outliner ignores the implicit `SP` def and happily outlines the tail call.
https://github.com/llvm/llvm-project/pull/230840
More information about the llvm-commits
mailing list