From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 88CB03858D3C; Wed, 20 Sep 2023 16:24:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88CB03858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695227053; bh=SePI5YnvHQM2W3hkaZza/JpwN6WKWlKVUSxIN9nWIYY=; h=From:To:Subject:Date:From; b=YVqj7X3wbOVsqDKT18i4QnwfNqXBdngXZhIL2uyI38ccm1kQuXpFQEWvnScg1MsA6 JZCXu9Uc0Y0B3+/74TwpeB/1UdizRMnczCA3ydvii/SwLymI+mTkhaiTmtIPSWE1N/ lvuDmiPxw83LhygNv/DcaLkccsKlKiz6xp4OePKk= From: "charlie at rivosinc dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111501] New: RISC-V: non-optimal casting when shifting Date: Wed, 20 Sep 2023 16:24:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: charlie at rivosinc dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111501 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=3D55949&action=3Dedit 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 seco= nd.=