<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 - llvm misses a chance to eliminate a scratch alloca used to swap two bignums"
   href="https://bugs.llvm.org/show_bug.cgi?id=38509">38509</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm misses a chance to eliminate a scratch alloca used to swap two bignums
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>vsk@apple.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example IR: <a href="https://godbolt.org/g/Uri5QR">https://godbolt.org/g/Uri5QR</a>

The optimizer misses a chance to eliminate %t1.i.i.i, a scratch alloca used to
swap the contents of two bignums within a loop in a typical `tmp = a; a = b; b
= tmp` pattern. It should be possible to swap these bignums by simply swapping
their pointers.

Here is the original Rust example: <a href="https://pastebin.com/0GGiX9yi">https://pastebin.com/0GGiX9yi</a>

```
sdrodge: It seems to me that the output assembly has an unnecessary write to
memory at line 27
sdrodge: And if that got optimized away, then 32 bytes of stack would be
unnecessary.
sdrodge: As it is, there's a whole 16 bytes that are never used, and 16 bytes
that are written to but never read from.
sdrodge: In other words, I think llvm should be able to figure out that the
%t1.i.i.i allocation is unnecessary and the swap can be done using registers.
sdrodge: and it _almost_ does?
sdrodge: just keeps one useless write and fails to optimized the allocation
away
```

Reported by sdrodge on IRC.</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>