When using the split sp adjustment and using the frame-pointer we were still emitting CFI CFA directives based on the sp value. The final sp-based offset also didn't reflect the two-stage sp adjust. There remain CFI issues that aren't related to the split sp adjustment, and thus will be addressed in a separate patch.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Hi @luismarques, thanks for fixing this.
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | ||
---|---|---|
198–207 | Could you add a comment before if(!hasFP(MF)) to describe that we don't need to generate .cfi_def_cfa_offset for SP adjustment after setting FP because the CFA calculation will base on FP after .cfi_def_cfa s0, 0 emission? | |
270 | It seems that we might be able to reduce the epilogue instructions if the FP exists. Something like: if (hasFP(MF) && !isInt<12>(SecondSPAdjustAmount)) { adjustReg(MBB, LastFrameDestroy, DL, SPReg, FPReg,-FirstSPAdjustAmount + RVFI->getVarArgsSaveSize(), MachineInstr::FrameDestroy); } else { adjustReg(MBB, LastFrameDestroy, DL, SPReg, SPReg, SecondSPAdjustAmount, MachineInstr::FrameDestroy); // Emit ".cfi_def_cfa_offset FirstSPAdjustAmount" unsigned CFIIndex = MF.addFrameInst( MCCFIInstruction::createDefCfaOffset(nullptr, -FirstSPAdjustAmount)); BuildMI(MBB, LastFrameDestroy, DL, TII->get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); } | |
293 | Should take variable arguments size into account |
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | ||
---|---|---|
270 | I would prefer to do codegen improvements in a separate patch. Thanks for the suggestion! |
Hi @luismarques, thanks for the patch, LGTM.
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | ||
---|---|---|
270 | Ok, that makes sense. |
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | ||
---|---|---|
294 | Is there a varargs-based test for this patch? |
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | ||
---|---|---|
294 | There is now. Good catch! :) |
The CFI directives look a lot more sane after this diff.
LGTM, I think this can be landed. We'll carefully watch the CI.
Could you add a comment before if(!hasFP(MF)) to describe that we don't need to generate .cfi_def_cfa_offset for SP adjustment after setting FP because the CFA calculation will base on FP after .cfi_def_cfa s0, 0 emission?