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

            Bug ID: 95014
           Summary: gcc fails to merge two identical returns
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rafael at espindo dot la
  Target Milestone: ---

Given

#include <new>
union any {
    any(any&& x) noexcept {
        if (x.st < 4) {
            st = x.st;
            x.st = 0;
        } else {
            ex = x.ex;
            x.ex = nullptr;
        }
    }
    long st;
    void* ex;
};
void f(any* a, any* b) {
    new (a) any(std::move(*b));
}

gcc produces

        movq    (%rsi), %rax
        movq    %rax, (%rdi)
        movq    $0, (%rsi)
        cmpq    $3, %rax
        jg      .L2
        ret
.L2:
        ret


clang produces

        movq    (%rsi), %rax
        cmpq    $3, %rax
        movq    %rax, (%rdi)
        movq    $0, (%rsi)
        retq

So clang has a redundant cmpq and gcc has the cmpq and two identical branch
destinations.

Reply via email to