public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111501] New: RISC-V: non-optimal casting when shifting
@ 2023-09-20 16:24 charlie at rivosinc dot com
  2023-09-20 16:31 ` [Bug target/111501] " palmer at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: charlie at rivosinc dot com @ 2023-09-20 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111501
           Summary: RISC-V: non-optimal casting when shifting
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: charlie at rivosinc dot com
  Target Milestone: ---

Created attachment 55949
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55949&action=edit
tar file of -save-temps output

I would expect the first to be able to compile into the second:

unsigned int do_shift(unsigned long csum)
{
        return (unsigned short)(csum >> 32);
}

unsigned int do_shift2(unsigned long csum)
{
        return (csum << 16) >> 48;
}

However, the asm output is instead:

do_shift:
        srli    a0,a0,32
        slli    a0,a0,48
        srli    a0,a0,48
        ret
do_shift2:
        slli    a0,a0,16
        srli    a0,a0,48
        ret

These are the same so the first should be able to be compiled into the second.

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

* [Bug target/111501] RISC-V: non-optimal casting when shifting
  2023-09-20 16:24 [Bug c/111501] New: RISC-V: non-optimal casting when shifting charlie at rivosinc dot com
@ 2023-09-20 16:31 ` palmer at gcc dot gnu.org
  2023-09-20 16:34 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: palmer at gcc dot gnu.org @ 2023-09-20 16:31 UTC (permalink / raw)
  To: gcc-bugs

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

palmer at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-09-20
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
          Component|c                           |target
     Ever confirmed|0                           |1
                 CC|                            |palmer at gcc dot gnu.org,
                   |                            |vineetg at gcc dot gnu.org

--- Comment #1 from palmer at gcc dot gnu.org ---
Adding Vineet.

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

* [Bug target/111501] RISC-V: non-optimal casting when shifting
  2023-09-20 16:24 [Bug c/111501] New: RISC-V: non-optimal casting when shifting charlie at rivosinc dot com
  2023-09-20 16:31 ` [Bug target/111501] " palmer at gcc dot gnu.org
@ 2023-09-20 16:34 ` pinskia at gcc dot gnu.org
  2024-05-06 19:58 ` cmuellner at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-20 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think there might be a dup of this bug already.

Also with zbb, GCC gets:

        srli    a0,a0,32
        zext.h  a0,a0
        ret

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

* [Bug target/111501] RISC-V: non-optimal casting when shifting
  2023-09-20 16:24 [Bug c/111501] New: RISC-V: non-optimal casting when shifting charlie at rivosinc dot com
  2023-09-20 16:31 ` [Bug target/111501] " palmer at gcc dot gnu.org
  2023-09-20 16:34 ` pinskia at gcc dot gnu.org
@ 2024-05-06 19:58 ` cmuellner at gcc dot gnu.org
  2024-05-06 20:15 ` vineetg at gcc dot gnu.org
  2024-05-16  9:15 ` cmuellner at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cmuellner at gcc dot gnu.org @ 2024-05-06 19:58 UTC (permalink / raw)
  To: gcc-bugs

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

Christoph Müllner <cmuellner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |cmuellner at gcc dot gnu.org
                 CC|                            |cmuellner at gcc dot gnu.org

--- Comment #3 from Christoph Müllner <cmuellner at gcc dot gnu.org> ---
I noticed this a while ago as well (when working on the XTheadB* stuff).
This can be addressed with an insn_and_split for zero_extract.
I even wrote a patch for that back then, but forgot to send it out.
I've rebased/retested it now and will send it once the release is out.

Btw, LLVM is catching all of these cases.

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

* [Bug target/111501] RISC-V: non-optimal casting when shifting
  2023-09-20 16:24 [Bug c/111501] New: RISC-V: non-optimal casting when shifting charlie at rivosinc dot com
                   ` (2 preceding siblings ...)
  2024-05-06 19:58 ` cmuellner at gcc dot gnu.org
@ 2024-05-06 20:15 ` vineetg at gcc dot gnu.org
  2024-05-16  9:15 ` cmuellner at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vineetg at gcc dot gnu.org @ 2024-05-06 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Vineet Gupta <vineetg at gcc dot gnu.org> ---
Awesome !

The trunk is open and new stuff, RISC-V certainly, is already landing, so no
harm in sending it now ;-)

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

* [Bug target/111501] RISC-V: non-optimal casting when shifting
  2023-09-20 16:24 [Bug c/111501] New: RISC-V: non-optimal casting when shifting charlie at rivosinc dot com
                   ` (3 preceding siblings ...)
  2024-05-06 20:15 ` vineetg at gcc dot gnu.org
@ 2024-05-16  9:15 ` cmuellner at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cmuellner at gcc dot gnu.org @ 2024-05-16  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

Christoph Müllner <cmuellner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Christoph Müllner <cmuellner at gcc dot gnu.org> ---
Closing this, as it has been fixed on master.

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

end of thread, other threads:[~2024-05-16  9:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 16:24 [Bug c/111501] New: RISC-V: non-optimal casting when shifting charlie at rivosinc dot com
2023-09-20 16:31 ` [Bug target/111501] " palmer at gcc dot gnu.org
2023-09-20 16:34 ` pinskia at gcc dot gnu.org
2024-05-06 19:58 ` cmuellner at gcc dot gnu.org
2024-05-06 20:15 ` vineetg at gcc dot gnu.org
2024-05-16  9:15 ` cmuellner 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).