public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/109035] New: meaningless memory store on RISC-V and LoongArch
@ 2023-03-06  7:51 xry111 at gcc dot gnu.org
  2023-03-06  7:52 ` [Bug rtl-optimization/109035] " xry111 at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-03-06  7:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109035

            Bug ID: 109035
           Summary: meaningless memory store on RISC-V and LoongArch
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

On LoongArch, without -fPIE, the compiler stores a register with no reason:

$ cat t.c
int test(int x)
{
        char buf[128 << 10];
        return buf[x];
}
$ ./gcc/cc1 t.c -nostdinc  -O2 -fdump-rtl-all -o- 2>/dev/null | grep test: -A20
test:
.LFB0 = .
        lu12i.w $r13,-135168>>12                        # 0xfffffffffffdf000
        ori     $r13,$r13,4080
        add.d   $r3,$r3,$r13
.LCFI0 = .
        lu12i.w $r12,-131072>>12                        # 0xfffffffffffe0000
        lu12i.w $r13,131072>>12                 # 0x20000
        add.d   $r13,$r13,$r12
        addi.d  $r12,$r3,16
        add.d   $r12,$r13,$r12
        lu12i.w $r13,131072>>12                 # 0x20000
        st.d    $r12,$r3,8
        ori     $r13,$r13,16
        ldx.b   $r4,$r12,$r4
        add.d   $r3,$r3,$r13
.LCFI1 = .
        jr      $r1
.LFE0:
        .size   test, .-test
        .section        .eh_frame,"aw",@progbits

Note the "st.d  $r12,$r3,8" instruction is completely meaningless.

The t.c.300r.ira dump contains some "interesting" thing:

Pass 0 for finding pseudo/allocno costs

    a0 (r87,l0) best GR_REGS, allocno GR_REGS
    a1 (r84,l0) best NO_REGS, allocno NO_REGS
    a2 (r83,l0) best GR_REGS, allocno GR_REGS

  a0(r87,l0) costs: SIBCALL_REGS:2000,2000 JIRL_REGS:2000,2000
CSR_REGS:2000,2000 GR_REGS:2000,2000 FP_REGS:8000,8000 ALL_REGS:32000,32000
MEM:8000,8000
  a1(r84,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000
CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000
ALL_REGS:1016000,1016000 MEM:1004000,1004000
  a2(r83,l0) costs: SIBCALL_REGS:1000000,1000000 JIRL_REGS:1000000,1000000
CSR_REGS:1000000,1000000 GR_REGS:1000000,1000000 FP_REGS:1004000,1004000
ALL_REGS:1008000,1008000 MEM:1004000,1004000

Here r84 is the pseudo register for ($frame - 131072).  Any idea why the
compiler selects "NO_REGS" here?

On RISC-V there is also a meaningless "sd      a5,8(sp)" instruction:
https://godbolt.org/z/aPorqj73b

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

end of thread, other threads:[~2023-11-03  7:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06  7:51 [Bug rtl-optimization/109035] New: meaningless memory store on RISC-V and LoongArch xry111 at gcc dot gnu.org
2023-03-06  7:52 ` [Bug rtl-optimization/109035] " xry111 at gcc dot gnu.org
2023-03-06  8:02 ` xry111 at gcc dot gnu.org
2023-03-08  3:16 ` chenglulu at loongson dot cn
2023-03-08  3:37 ` xry111 at gcc dot gnu.org
2023-03-08  3:55 ` chenglulu at loongson dot cn
2023-03-11  6:44 ` chenglulu at loongson dot cn
2023-03-11  7:00 ` chenglulu at loongson dot cn
2023-11-02 19:25 ` vmakarov at gcc dot gnu.org
2023-11-02 19:47 ` law at gcc dot gnu.org
2023-11-03  6:52 ` xry111 at gcc dot gnu.org
2023-11-03  7:46 ` xry111 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).