[Bug tree-optimization/68557] New: Missed x86 peephole optimization for multiplying by a bool

ppalka at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 26 14:00:00 GMT 2015


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

            Bug ID: 68557
           Summary: Missed x86 peephole optimization for multiplying by a
                    bool
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

On x86 the following code

void bar (int x);

void
baz (int x, bool b)
{
  bar (x * b);
}


is compiled to


bar:
        movzbl  %sil, %esi
        imull   %esi, %edi
        jmp     baz


when it could instead be compiled to

bar:
        movzbl  %sil, %esi
        negl    %esi
        andl    %esi, %edi
        jmp     baz


On modern processors the "neg" and "and" instructions takes a minimum of one
cycle each, whereas the "imul" instruction takes a minimum three cycles.  So
transforming "x * (int)b" to "x & -(int)b" would save one cycle in the best
case.


More information about the Gcc-bugs mailing list