[Bug c/70087] Different (worse?) code generated for "if (a || (b || c))" vs "if (a || b || c)"

dmalcolm at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 4 20:23:00 GMT 2016


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

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org

--- Comment #3 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
FWIW, doing it as a switch leads to a branch also:

int baz ()
{
  switch (at)
    {
    case 2:
    case 4:
    case 7:
      return 1;
    default:
      return 0;
    }
}

baz:
.LFB2:
        .cfi_startproc
        movl    at(%rip), %ecx
        xorl    %eax, %eax
        cmpl    $7, %ecx
        ja      .L7
        movl    $1, %eax
        salq    %cl, %rax
        testb   $-108, %al
        setne   %al
.L7:
        movzbl  %al, %eax
        ret
        .cfi_endproc

where switchconv printed "expanding as bit test is preferable".


More information about the Gcc-bugs mailing list