public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/115687] New: RISC-V optimization when "lui" instructions can be merged
@ 2024-06-27 17:51 Explorer09 at gmail dot com
  2024-06-27 18:17 ` [Bug target/115687] " palmer at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Explorer09 at gmail dot com @ 2024-06-27 17:51 UTC (permalink / raw)
  To: gcc-bugs

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
```

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

end of thread, other threads:[~2024-06-27 21:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-27 17:51 [Bug other/115687] New: RISC-V optimization when "lui" instructions can be merged Explorer09 at gmail dot com
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

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