[llvm] [PowerPC]optimize the epilogue for restore non volatile cr fields (PR #202339)

zhijian lin via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 06:34:26 PDT 2026


================
@@ -1768,6 +1769,22 @@ void PPCFrameLowering::emitEpilogue(MachineFunction &MF,
     }
   }
   assert(RBReg != ScratchReg && "Should have avoided ScratchReg");
+
+  auto BuildMoveToCR = [&]() {
+    if (MustSaveCRs.size() == 1) {
+      // In Non 32 Bit ELF ABI, we are not required to restore all CR fields.
+      // If only one CR field was clobbered, use mtocrf to selectively
+      // restore just that field.
+      assert(!Subtarget.is32BitELFABI() && "Non 32 Bit ELF ABI only.");
----------------
diggerlin wrote:

in the function PPCFrameLowering::restoreCalleeSavedRegisters

there is 
1. https://github.com/diggerlin/llvm-project/blob/digger/non-volatile-cr-clobber-new/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp#L2651C1-L2652C16
2. https://github.com/diggerlin/llvm-project/blob/digger/non-volatile-cr-clobber-new/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp#L2729-L2734

for Subtarget.is32BitELFABI() , it restore the non-volatile CR fields in the function restoreCRs

for !Subtarget.is32BitELFABI(), it restore the non-volatile CR fields in the  funciont  PPCFrameLowering::emitEpilogue
so I add an assert here, but it maybe better to move the assert to before the` if (MustSaveCRs.size() == 1) `

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


More information about the llvm-commits mailing list