[llvm] [AArch64] Fix miscompilation due to integer overflow in immediate offset for stack store/load instructions with preserve_all (PR #207026)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 01:51:16 PDT 2026
================
@@ -2651,8 +2658,19 @@ void AArch64FrameLowering::determineCalleeSaves(MachineFunction &MF,
ZPRCSStackSize += SpillSize;
else if (IsPPR)
PPRCSStackSize += SpillSize;
- else
- CSStackSize += SpillSize;
+ else {
+ // A register and its super-register can both appear in SavedRegs.
+ // Only the widest register is actually spilled, so skip such
+ // sub-registers here to avoid double-counting the overlap.
+ bool SavedSuper = false;
+ for (MCPhysReg SuperReg : TRI->superregs(MCRegister(Reg)))
+ if (SavedRegs.test(SuperReg)) {
+ SavedSuper = true;
+ break;
+ }
+ if (!SavedSuper)
+ CSStackSize += SpillSize;
----------------
MacDue wrote:
It's shorter, but I'd say it's still clearer to move the test out of the condition, like:
```c++
bool SavedSuper = any_of(TRI->superegs(Reg), [&](MCPhysReg Reg) {
return SavedReg.test(SuperReg);
});
if (!SavedSuper)
CSStackSize += SpillSize;
```
https://github.com/llvm/llvm-project/pull/207026
More information about the llvm-commits
mailing list