<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - CloneMachineInstr doesn't clone machine instructions' register ties, but claims it does"
   href="https://bugs.llvm.org/show_bug.cgi?id=40079">40079</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CloneMachineInstr doesn't clone machine instructions' register ties, but claims it does
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>harald@gigawatt.nl
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>CloneMachineInstr creates a new machine instruction by copying all operands one
by one. Copying operands does not preserve all information. In particular,
copying operands one by one does not and cannot preserve register ties.

CloneMachineInstr's documentation suggests that it does preserve register ties:

MachineFunction.cpp:326:
<span class="quote">> /// Create a new MachineInstr which is a copy of the 'Orig' instruction,
> /// identical in all ways except the instruction has no parent, prev, or next.</span >

MachineFunction.h:691:
<span class="quote">> /// Create a new MachineInstr which is a copy of \p Orig, identical in all
> /// ways except the instruction has no parent, prev, or next. Bundling flags
> /// are reset.
> ///
> /// Note: Clones a single instruction, not whole instruction bundles.
> /// Does not perform target specific adjustments; consider using
> /// TargetInstrInfo::duplicate() instead.</span >

Register ties are not about instruction bundles and not target-specific (even
if the reason for the ties is), so I'm not seeing anything in there to say that
ties should be reset.

Either CloneMachineInstr should document that it does not and should not
preserve this, or it should be fixed so that it does preserve it.

Seen in a project based on LLVM 4.0.1, but checked against git master
(f6775ea3ff7d9b047204560b02db191b6dbfb907):

CloneMachineInstr (MachineFunction.cpp:329) invokes MachineInstr's
copy-like-constructor.
MachineInstr's constructor (MachineInstr.cpp:134) calls addOperand for each of
the source instruction's operands.
addOperand invokes MachineOperand's copy constructor (MachineInstr.cpp:262),
but then explicitly drops ties (MachineInstr.cpp:270) and only sets up ties
again when the instruction is marked so (MachineInstr.cpp:282).

When the source instruction has tied imp-use registers, there is nothing to
restore those ties.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>