<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 - When same reg is used for output and implicit-def, spill is inserted and overwrites output result"
   href="https://bugs.llvm.org/show_bug.cgi?id=41790">41790</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>When same reg is used for output and implicit-def, spill is inserted and overwrites output result
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </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>Register Allocator
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>code.kchoi@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, quentin.colombet@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>(Paste from @llvm.dev) I ran into a case where RegAlloc would insert a spill
across instruction that had same register for output operand and implicit-def.
The effect this had was that spill code would immediately overwrite the output
result. Is this the expected result of setting up MyInst this way? In other
words, does RegAlloc know to not insert spill in case it sees that output reg
is same as one of implicit-def?

If this is intended (always spilling live regs across implicit-def inst?), I am
puzzled on how to use MyInst that has variable output reg with static
implicit-defs. Any tips would be greatly appreciated.

Reduced Example:
Before RegAlloc:
%1:reg = COPY ...;
%2:reg = MyInst %1:reg, ..., implicit-def dead $p1, ...;
%3:reg = Use %2:reg

RegAlloc:
<span class="quote">>> %2:reg = MyInst %1:reg, ..., implicit-def dead $p1, ...;</span >
Regs: $p1=%1
Killing last use: %1:reg
Assigning %2 to $p1
Spilling %2 in $p1 to stack slot #2  <-- suspicious if this is inserting spill,
unaware of output reg being same
<< $p1 =MyInst killed $p1, ..., implicit-def dead $p1, ...;

After RegAlloc:
$p1 = COPY ...;
Store $p1 %stack.2;
$p1 =MyInst killed $p1, ..., implicit-def dead $p1, ...;
$p1 = Load %stack.2;
$p2 = Use $p1, ...;</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>