[llvm-bugs] [Bug 38509] New: llvm misses a chance to eliminate a scratch alloca used to swap two bignums

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 9 18:01:21 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38509

            Bug ID: 38509
           Summary: llvm misses a chance to eliminate a scratch alloca
                    used to swap two bignums
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: vsk at apple.com
                CC: llvm-bugs at lists.llvm.org

Example IR: https://godbolt.org/g/Uri5QR

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: https://pastebin.com/0GGiX9yi

```
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180810/acebbe10/attachment.html>


More information about the llvm-bugs mailing list