public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "Explorer09 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug other/115687] New: RISC-V optimization when "lui" instructions can be merged Date: Thu, 27 Jun 2024 17:51:11 +0000 [thread overview] Message-ID: <bug-115687-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115687 Bug ID: 115687 Summary: RISC-V optimization when "lui" instructions can be merged Product: gcc Version: 14.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: Explorer09 at gmail dot com Target Milestone: --- ```c #include <stdio.h> int main() { unsigned int a = 0x4010; // (0x4 << 12) + 0x10 unsigned int b = 0x4020; // (0x4 << 12) + 0x20 unsigned int c = 0x3FF0; // (0x4 << 12) - 0x10 printf("0x%08x 0x%08x 0x%08x\n", a, b, c); return 0; } ``` RISC-V (64-bits) GCC 14.1 with -Os option produces: ```text li a3,16384 li a2,16384 li a1,16384 lui a0,%hi(.LC0) addi sp,sp,-16 addi a3,a3,-16 addi a2,a2,32 addi a1,a1,16 addi a0,a0,%lo(.LC0) sd ra,8(sp) call printf ld ra,8(sp) li a0,0 addi sp,sp,16 jr ra ``` There are three "li ...,16384" instructions generated, while it is possible to reduce them to one. For example, by using the same "a1" register for the addends: ```text li a1,16384 ... addi a3,a1,-16 addi a2,a1,32 addi a1,a1,16 ```
next reply other threads:[~2024-06-27 17:51 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-06-27 17:51 Explorer09 at gmail dot com [this message] 2024-06-27 18:17 ` [Bug target/115687] " palmer at gcc dot gnu.org 2024-06-27 18:30 ` pinskia at gcc dot gnu.org 2024-06-27 18:32 ` pinskia at gcc dot gnu.org 2024-06-27 18:49 ` palmer at gcc dot gnu.org 2024-06-27 18:54 ` palmer at gcc dot gnu.org 2024-06-27 20:39 ` andrew at sifive dot com 2024-06-27 21:02 ` vineetg at gcc dot gnu.org 2024-06-27 21:57 ` palmer at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-115687-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).