public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66663] New: gcc misses optimization emits useless test of (a & 31) with 32
@ 2015-06-25 12:02 fuz at fuz dot su
  2015-06-25 12:14 ` [Bug c/66663] " fuz at fuz dot su
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fuz at fuz dot su @ 2015-06-25 12:02 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-27  0:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-25 12:02 [Bug c/66663] New: gcc misses optimization emits useless test of (a & 31) with 32 fuz at fuz dot su
2015-06-25 12:14 ` [Bug c/66663] " fuz at fuz dot su
2021-07-27  0:01 ` [Bug target/66663] " pinskia at gcc dot gnu.org
2021-07-27  0:05 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).