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

* [Bug c/66663] gcc misses optimization emits useless test of (a & 31) with 32
  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 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: fuz at fuz dot su @ 2015-06-25 12:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Robert Clausecker <fuz at fuz dot su> ---
Sorry. I meant to say: The branch will always be taken, not never.


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

* [Bug target/66663] gcc misses optimization emits useless test of (a & 31) with 32
  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 ` pinskia at gcc dot gnu.org
  2021-07-27  0:05 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27  0:01 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |9.0
         Resolution|---                         |FIXED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC 9+ is able to produce:
foo(unsigned long long, int):
.LFB0:
        .cfi_startproc
        movl    4(%esp), %eax
        movl    12(%esp), %ecx
        movl    8(%esp), %edx
        shldl   %eax, %edx
        sall    %cl, %eax
        ret

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

* [Bug target/66663] gcc misses optimization emits useless test of (a & 31) with 32
  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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27  0:05 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |DUPLICATE

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It was fixed by r9-62 which means this is a dup of bug 84431.

*** This bug has been marked as a duplicate of bug 84431 ***

^ 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).