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

            Bug ID: 85224
           Summary: x86_64 missed optimisation opportunity for (-1 * !!x)
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vegard.nossum at oracle dot com
  Target Milestone: ---

Input:

int f(int x) {
  return -1 * !!x;
}

Trunk with -O3 gives:

f(int):
  xor eax, eax
  test edi, edi
  setne al
  neg eax
  ret

While clang -O3 gives:

f: # @f
  neg edi
  sbb eax, eax
  ret

gcc -O1 gives a different sequence which is slightly longer:

f(int):
  test edi, edi
  setne al
  movzx eax, al
  neg eax
  ret

Reply via email to