[Bug target/85234] New: missed optimisation opportunity for (~x >> n) ? a : b with n, a, b constants

vegard.nossum at oracle dot com gcc-bugzilla@gcc.gnu.org
Thu Apr 5 14:46:00 GMT 2018


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

            Bug ID: 85234
           Summary: missed optimisation opportunity for (~x >> n) ? a : b
                    with n, a, b constants
           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
                CC: segher at gcc dot gnu.org
  Target Milestone: ---
            Target: x86_64-*-*, i?86-*-*

Input:

int x;

int f()
{
    return (~x >> 3) ? 1030355390 : 1367354703;
}

With -O3, trunk outputs:

f():
  movl x(%rip), %eax
  notl %eax
  sarl $3, %eax
  cmpl $1, %eax
  sbbl %eax, %eax
  andl $336999313, %eax
  addl $1030355390, %eax
  ret

Clang (also at -O3), however, outputs:

f(): # @f()
  cmpl $-8, x(%rip)
  movl $1030355390, %ecx # imm = 0x3D69F9BE
  movl $1367354703, %eax # imm = 0x51802D4F
  cmovbl %ecx, %eax
  retq


More information about the Gcc-bugs mailing list