[llvm-bugs] [Bug 43915] New: Missed optimizations for std::optional<int>::emplace()

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 6 01:53:23 PST 2019


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

            Bug ID: 43915
           Summary: Missed optimizations for std::optional<int>::emplace()
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: redbeard0531 at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

https://godbolt.org/z/6-0fT3

#include <optional>
std::optional<int> x;
void test() {
    x.emplace(7);
}

clang -O3 codegen: 
test():                               # @test()
        cmp     byte ptr [rip + x+4], 0
        je      .LBB0_2
        mov     byte ptr [rip + x+4], 0
.LBB0_2:
        mov     dword ptr [rip + x], 7
        mov     byte ptr [rip + x+4], 1
        ret

Note the double store to [rip + x+4]. If the initial store was eliminated, that
should also kill the unnecessary comparison+branch because the end result is
the same regardless of the initial state of the object.

gcc -O3 codegen:
test():
        mov     DWORD PTR x[rip], 7
        mov     BYTE PTR x[rip+4], 1
        ret

-- 
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/20191106/289c862e/attachment.html>


More information about the llvm-bugs mailing list