[llvm] RegisterCoalescer: Fix producing malformed IMPLICIT_DEFs (PR #73784)

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 3 08:35:00 PST 2023


================
@@ -1694,12 +1694,19 @@ MachineInstr *RegisterCoalescer::eliminateUndefCopy(MachineInstr *CopyMI) {
   // The source interval may also have been on an undef use, in which case the
   // copy introduced a live value.
   if (((V && V->isPHIDef()) || (!V && !DstLI.liveAt(Idx)))) {
-    CopyMI->setDesc(TII->get(TargetOpcode::IMPLICIT_DEF));
     for (unsigned i = CopyMI->getNumOperands(); i != 0; --i) {
       MachineOperand &MO = CopyMI->getOperand(i-1);
-      if (MO.isReg() && MO.isUse())
+      if (MO.isReg()) {
+        if (MO.isUse())
+          CopyMI->removeOperand(i - 1);
+      } else {
+        assert(MO.isImm() &&
+               (CopyMI->getOpcode() == TargetOpcode::SUBREG_TO_REG));
----------------
kparzysz wrote:

Right, but the fact that the only copy-like instruction is `SUBREG_TO_REG` is not at all evident.  In my reading of the code this looks like "out of all copy-like instructions, only SUBREG_TO_REG is allowed to have an immediate operand", so the question comes to mind "what is special about SUBREG_TO_REG?".

This is obviously subjective.  Feel free to commit as-is.  I'm just sharing my perspective on this.

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


More information about the llvm-commits mailing list