This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/71336] New: Suboptimal x86 code generated for "(a & 1) ? (CST1 + CST2) : CST1"


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

            Bug ID: 71336
           Summary: Suboptimal x86 code generated for "(a & 1) ? (CST1 +
                    CST2) : CST1"
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

$ cat test.c
int test(int a) {
    return a & 1 ? 7 : 3;
}
$ gcc -O2 -o- -S test.c
test:
.LFB0:
        .cfi_startproc
        andl    $1, %edi
        cmpl    $1, %edi
        sbbl    %eax, %eax
        andl    $-4, %eax
        addl    $7, %eax
        ret
        .cfi_endproc

The optimal code would look like

        andl    $1, %edi
        leal    3(,%rdi,4), %eax
        ret

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]