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

            Bug ID: 88797
           Summary: Unneeded branch added when function is inlined
                    (function runs faster if not inlined)
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cassio.neri at gmail dot com
  Target Milestone: ---

Consider:

void use(unsigned);
bool f(unsigned x, unsigned y) {
    return x < 1111 + (y <= 2222);
}
void test_f(unsigned x, unsigned y) {
    for (unsigned i = 0; i < 3333; ++i)
        use(f(x++, y++));
}

The generated code for f seems fine and the there's no branch to test y <=
2222:

f(unsigned int, unsigned int):
  xorl %eax, %eax
  cmpl $2222, %esi
  setbe %al
  addl $1111, %eax
  cmpl %edi, %eax
  seta %al
  ret

However, when f is inlined in test_f, a branch is introduced to decide whether
x should be compared to 1111 or 1112 (code cut for brevity)

test_f(unsigned int, unsigned int):
  [...]
  jmp .L6
.L14:
  cmpl $1111, %eax
.L12:
  [...]
.L6:
  [...]
  cmpl $2222, %ebx
  jbe .L14
  cmpl $1110, %eax
  jmp .L12
  [...]

See https://godbolt.org/z/_EC992 use -O3.

This seems to be a regression: it used to be OK up to 6.3 and then degraded in
7.1 (according to godbolt).

Reply via email to