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

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