[llvm] [M68k] Prevent COPY instruction from killing live condition flags (PR #168485)

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 4 07:55:57 PDT 2026


================
@@ -690,86 +690,142 @@ void M68kInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
                                 const DebugLoc &DL, Register DstReg,
                                 Register SrcReg, bool KillSrc,
                                 bool RenamableDest, bool RenamableSrc) const {
-  const auto &Subtarget = MBB.getParent()->getSubtarget<M68kSubtarget>();
   unsigned Opc = 0;
+  MachineFunction &MF = *MBB.getParent();
+  const M68kSubtarget &STI = MF.getSubtarget<M68kSubtarget>();
 
-  // First deal with the normal symmetric copies.
-  if (M68k::XR32RegClass.contains(DstReg, SrcReg))
+  // Symmetric register copies
+  if (M68k::XR32RegClass.contains(DstReg, SrcReg)) {
     Opc = M68k::MOV32rr;
-  else if (M68k::XR16RegClass.contains(DstReg, SrcReg))
+  } else if (M68k::XR16RegClass.contains(DstReg, SrcReg)) {
     Opc = M68k::MOV16rr;
-  else if (M68k::DR8RegClass.contains(DstReg, SrcReg))
+  } else if (M68k::DR8RegClass.contains(DstReg, SrcReg)) {
     Opc = M68k::MOV8dd;
-
-  if (Opc) {
-    BuildMI(MBB, MI, DL, get(Opc), DstReg)
-        .addReg(SrcReg, getKillRegState(KillSrc));
-    return;
   }
 
-  // Now deal with asymmetrically sized copies. The cases that follow are upcast
-  // moves.
-  //
-  // NOTE
-  // These moves are not aware of type nature of these values and thus
-  // won't do any SExt or ZExt and upper bits will basically contain garbage.
-  MachineInstrBuilder MIB(*MBB.getParent(), MI);
-  if (M68k::DR8RegClass.contains(SrcReg)) {
-    if (M68k::XR16RegClass.contains(DstReg))
-      Opc = M68k::MOVXd16d8;
-    else if (M68k::XR32RegClass.contains(DstReg))
-      Opc = M68k::MOVXd32d8;
+  // Asymmetric register copies
+  // NOTE: There is no implicit sext/zext occurring during these moves, so the
+  // upper bits will be undefined.
+  // 8 -> 16
+  else if (M68k::DR8RegClass.contains(SrcReg) &&
----------------
jrtc27 wrote:

clang-format doesn't scream about it, but is this style of shoving a comment between `}` and `else` really conforming? It's not the most readable.

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


More information about the llvm-commits mailing list