http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58073

--- Comment #1 from dhowells at redhat dot com <dhowells at redhat dot com> ---
Interestingly, the suboptimality shifts if the 'shift' value in the demo
program is changed to 0:

Going through the cases individually::

 (1) return (mask(d) == (0x0 << shift));

This is rendered as a single TEST instruction in x86_64 asm:

   0:   f6 07 07                testb  $0x7,(%rdi)
   3:   0f 94 c0                sete   %al
   6:   c3                      retq   

which is fine.

 (2) return (mask(d) == (0x0 << shift) ||
                mask(d) == (0x1 << shift));

is rendered as:

  10:   8b 07                   mov    (%rdi),%eax
  12:   83 e0 07                and    $0x7,%eax
  15:   83 f8 01                cmp    $0x1,%eax
  18:   0f 96 c0                setbe  %al
  1b:   c3                      retq   

which is not what I'd expect.  What happened to the single TEST instruction
that was produced for shift = 4?

And then:

 (3) return (mask(d) == (0x0 << shift) ||
                   mask(d) == (0x1 << shift) ||
                   mask(d) == (0x2 << shift));

which is rendered as:

  20:   8b 07                   mov    (%rdi),%eax
  22:   83 e0 07                and    $0x7,%eax
  25:   83 f8 02                cmp    $0x2,%eax
  28:   0f 96 c0                setbe  %al
  2b:   c3                      retq   

which is good (and which is similar to what I'd've expected case 3 to generate
when shift = 4).

Reply via email to