[llvm] [X86] Recognize POP/ADD/SUB modifying rsp in getSPAdjust. (PR #114265)

Daniel Zabawa via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 13:24:06 PST 2024


daniel-zabawa wrote:

I believe I've found the issue. When X86FrameLowering is handling the initial ADJCALLSTACKDOWN, the usual procedure is to insert the SP adjustment (SUB $rsp) at the ADJCALLSTACKDOWN site, with the returned iterator following the inserted SUB, as it's simply supplying the SP adjustment we already counted.

But, the insertion point actually skips debug instructions forward, and this is not accounted for in the result. So if debug instructions are present, the SUB inserted to replace the ADJCALLSTACKDOWN is visited again in the replaceFrameIndices loop, and is counted again towards the SP adjustment. This didn't happen before because we only recognized PUSH.

This is unfortunate as the prologepilog code apparently assumes the code replacing ADJCALLSTACKDOWN will not be visited in the loop. The original change to skip debug instructions when placing the replacement code traces back to https://bugs.llvm.org/show_bug.cgi?id=31319. 
 
The commit only mentions that debug instructions after the erased (replaced?) call-stack adjustment could affect codegen. Both of the test cases from the bug report produce the same results with -g with or without this change. The lits added (CodeGen/X86/frame-lowering-debug-intrinsic.ll, CodeGen/X86/frame-lowering-debug-intrinsic-2.ll) pass with or without this change.

I am at a loss why the SUB should appear after debug instructions when the ADJCALLSTACKDOWN originally preceded them. I'll have to dig a bit to figure out a case that justifies this. 


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


More information about the llvm-commits mailing list