https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93210

            Bug ID: 93210
           Summary: Sub-optimal code optimization on struct/combound
                    constexpr (gcc vs. clang)
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: markus.eisenmann at outlook dot com
  Target Milestone: ---

Created attachment 47617
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47617&action=edit
Sample-Code to show different optimization of gcc vs. clang

Hi,

The attached source-code shows that the current elease of GCC does not use the
given constexpr for a direct value-compare and needs a definition for a
indirect (mem-) operation. But, if the same compare uses a temporary copy, the
emitted code is optimal.

Additionaly, the comparision of assembler-output between gcc 9.2 to clang 9.0
will show, that clang will generate in booth cases a direct value-compare.
IMHO, a "more" sub-optimal code will be generated with the flag -fPIC; I.e. two
additional read-cycles.

Assembler-Code output 1 (x86-64 gcc 8.2, -O2):
[sub-optimal code of Bar::CheckId1]

    Bar::CheckId1(Foo const&) const:
        mov     rax, QWORD PTR [rsi]
        cmp     QWORD PTR Bar::Should[rip], rax
        sete    al
        ret
    Bar::CheckId2(Foo const&) const:
        movabs  rax, 180388626445
        cmp     rax, QWORD PTR [rsi]
        sete    al
        ret
    Bar::Should:
        .long   13
        .long   42
--------

Assembler-Code output 2 (x86-64 clang 9.0, -O2):
[same code for Bar::CheckId1 and CheckId2]

    Bar::CheckId1(Foo const&) const:
        movabs  rax, 180388626445
        cmp     qword ptr [rsi], rax
        sete    al
        ret
    Bar::CheckId2(Foo const&) const:
        movabs  rax, 180388626445
        cmp     qword ptr [rsi], rax
        sete    al
        ret
Bar::Should:
        .long   13                      # 0xd
        .long   42                      # 0x2a
--------

Best regards from Salzburg,
Markus

Reply via email to