[Bug c/66663] New: gcc misses optimization emits useless test of (a & 31) with 32

fuz at fuz dot su gcc-bugzilla@gcc.gnu.org
Thu Jun 25 12:02:00 GMT 2015


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

            Bug ID: 66663
           Summary: gcc misses optimization emits useless test of (a & 31)
                    with 32
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fuz at fuz dot su
  Target Milestone: ---

The following code:

    unsigned long long foo(unsigned long long x, int a) {
        return x << (a & 31);
    }

compiled with a recent build of gcc for i386 Linux (with -O3) yields the
following assembly:

    foo:
        movl    12(%esp), %ecx
        movl    4(%esp), %eax
        movl    8(%esp), %edx
        andl    $31, %ecx
        shldl   %eax, %edx
        sall    %cl, %eax
        testb   $32, %cl
        je      .L2
        movl    %eax, %edx
        xorl    %eax, %eax
.L2:
        rep ret

        .ident  "GCC: (GNU) 5.0.0 20150314 (experimental)"

The testb instruction seems redundant as %cl has been masked with $31 a few
instructions before: The jump will never be taken.



More information about the Gcc-bugs mailing list