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.