public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113951] New: regression redundant load
@ 2024-02-16  4:09 absoler at smail dot nju.edu.cn
  2024-02-16  9:58 ` [Bug rtl-optimization/113951] " rguenth at gcc dot gnu.org
  2024-04-06  1:52 ` [Bug rtl-optimization/113951] regression redundant load (-fschedule-insns) absoler at smail dot nju.edu.cn
  0 siblings, 2 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-02-16  4:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113951
           Summary: regression redundant load
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

Hi, here's the code:

```
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int int16_t;
typedef unsigned short int uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long int int64_t;
typedef unsigned long int uint64_t;

struct S1 {
   uint64_t  f0;
   uint64_t  f1;
   uint32_t  f2;
};

/* --- GLOBAL VARIABLES --- */
int32_t g_5 = 0xB779C63CL;
struct S1 g_441 = {0x387DADCAC0CA1ED2LL,18446744073709551606UL,4294967295UL};
uint16_t g_558 = 65534UL;
int32_t *g_560 = &g_5;
struct S1 *g_677 = &g_441;
uint32_t g_740 = 0UL;
struct S1 g_752 = {0UL,0xD68240D217006E9ALL,4294967295UL};

int f = 1;

int c;
void func_1() {
  int32_t b[1];
  if (g_5) {
    int32_t **d = &g_560;
    if (g_558) {
      *d = g_560;
      **d = 0;
    } else {
      int32_t e = (int)b;
      g_677 = &g_441;
    }
  } else {
    uint32_t f[5];
    b[0] = (int)f;
  }
  if (f)
    for (; c; c++)
      g_740--;
  *g_677 = g_752;
}
```

with -O2 flag, gcc-11.2.0 and gcc-13.2.0 with an extra option
"-fschedule-insns" can both generate the same following binary code:

```
0000000000401680 <func_1>:
func_1():
/root/myCSmith/test/output2.c:52
  401680:       mov    0x2a4e(%rip),%ecx        # 4040d4 <g_5>
/root/myCSmith/test/output2.c:68
  401686:       mov    0x29fb(%rip),%rax        # 404088 <g_677>
/root/myCSmith/test/output2.c:52
  40168d:       test   %ecx,%ecx
  40168f:       je     4016af <func_1+0x2f>
/root/myCSmith/test/output2.c:54
  401691:       cmpw   $0x0,0x29ff(%rip)        # 404098 <g_558>
  401699:       je     4016f0 <func_1+0x70>
/root/myCSmith/test/output2.c:56
  40169b:       mov    0x29ee(%rip),%rdx        # 404090 <g_560>
/root/myCSmith/test/output2.c:68
  4016a2:       mov    0x29df(%rip),%rax        # 404088 <g_677>
/root/myCSmith/test/output2.c:56
  4016a9:       movl   $0x0,(%rdx)
/root/myCSmith/test/output2.c:65
  4016af:       mov    0x29ab(%rip),%edx        # 404060 <f>
  4016b5:       test   %edx,%edx
  4016b7:       je     4016d3 <func_1+0x53>
/root/myCSmith/test/output2.c:66 (discriminator 1)
  4016b9:       mov    0x10549(%rip),%edx        # 411c08 <c>
  4016bf:       test   %edx,%edx
  4016c1:       je     4016d3 <func_1+0x53>
  4016c3:       add    %edx,0x10543(%rip)        # 411c0c <g_740>
  4016c9:       movl   $0x0,0x10535(%rip)        # 411c08 <c>
/root/myCSmith/test/output2.c:68
  4016d3:       movdqa 0x2995(%rip),%xmm0        # 404070 <g_752>
  4016db:       movups %xmm0,(%rax)
  4016de:       mov    0x299b(%rip),%rdx        # 404080 <g_752+0x10>
  4016e5:       mov    %rdx,0x10(%rax)
/root/myCSmith/test/output2.c:69
  4016e9:       retq   
  4016ea:       nopw   0x0(%rax,%rax,1)
/root/myCSmith/test/output2.c:59
  4016f0:       movq   $0x4040a0,0x298d(%rip)        # 404088 <g_677>
  4016fb:       mov    $0x4040a0,%eax
  401700:       jmp    4016af <func_1+0x2f>
  401702:       data16 nopw %cs:0x0(%rax,%rax,1)
  40170d:       nopl   (%rax)
```

we can see g_677 has been load repeatedly both at 0x401686 and 0x4016a2 at
runtime, it's not necessary

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

* [Bug rtl-optimization/113951] regression redundant load
  2024-02-16  4:09 [Bug target/113951] New: regression redundant load absoler at smail dot nju.edu.cn
@ 2024-02-16  9:58 ` rguenth at gcc dot gnu.org
  2024-04-06  1:52 ` [Bug rtl-optimization/113951] regression redundant load (-fschedule-insns) absoler at smail dot nju.edu.cn
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-02-16  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
          Component|target                      |rtl-optimization
             Target|                            |x86_64-*-*
   Last reconfirmed|                            |2024-02-16

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  There's no CSE between sched1 and RA and while GCSE after RA sees
both loads:

expr: (mem/f/c:DI (symbol_ref:DI ("g_677") [flags 0x2]  <var_decl
0x7ffff6a19ea0 g_677>) [3 g_677+0 S8 A64])
hashcode: 2958100634
list of occurrences:
(insn 19 16 57 5 (set (reg/f:DI 0 ax [orig:104 pretmp_21 ] [104])
        (mem/f/c:DI (symbol_ref:DI ("g_677") [flags 0x2]  <var_decl
0x7ffff6a19ea0 g_677>) [3 g_677+0 S8 A64])) "t.c":46:3 84 {*movdi_internal}
     (nil))

(insn 9 8 52 3 (set (reg/f:DI 0 ax [orig:104 pretmp_21 ] [104])
        (mem/f/c:DI (symbol_ref:DI ("g_677") [flags 0x2]  <var_decl
0x7ffff6a19ea0 g_677>) [3 g_677+0 S8 A64])) "t.c":46:3 84 {*movdi_internal}
     (nil))

it doesn't do anything here.

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

* [Bug rtl-optimization/113951] regression redundant load (-fschedule-insns)
  2024-02-16  4:09 [Bug target/113951] New: regression redundant load absoler at smail dot nju.edu.cn
  2024-02-16  9:58 ` [Bug rtl-optimization/113951] " rguenth at gcc dot gnu.org
@ 2024-04-06  1:52 ` absoler at smail dot nju.edu.cn
  1 sibling, 0 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-04-06  1:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from absoler at smail dot nju.edu.cn ---
after sched1 modified the code, ce3 introduced this extra load. un-sched1 code
would not be pessimised by ce3

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

end of thread, other threads:[~2024-04-06  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16  4:09 [Bug target/113951] New: regression redundant load absoler at smail dot nju.edu.cn
2024-02-16  9:58 ` [Bug rtl-optimization/113951] " rguenth at gcc dot gnu.org
2024-04-06  1:52 ` [Bug rtl-optimization/113951] regression redundant load (-fschedule-insns) absoler at smail dot nju.edu.cn

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