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

            Bug ID: 113107
           Summary: miss optimization of an unmerged load operation
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

Created attachment 56916
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56916&action=edit
source file

I found a redundant load introduced by O2 optimization, and this behavior is
regression, confirmed on gcc 7.2.0, 12.2.0 and 13.2.0 (from 4.2 to 13.2 are
tested)

given this code:

```
int g_30 = 0L;
int g_56[7] = {(-1L),(-1L),(-1L),(-1L),(-1L),(-1L),(-1L)};
unsigned long long g_118 = 18446744073709551607UL;


int  func_65(unsigned  p_67);
int * func_69(int  p_74);

int g, arg;
unsigned func_1() { func_65(arg); }

int func_65(unsigned a) {
  func_69(a);
  g = g_56[4] < (g_56[5] || a);
}

int *func_69(int d) {
  if (d)
    return (void*)0;
  int64_t f[109] = {};
  --g_118;
  g_30 = 0;
  return (void*)0;
}

```

the disassemlbly of `func_65` are: (dump with objdump)

```
00000000004015e0 <func_65>:
func_65():
/root/myCSmith/test/output2.c:39
  4015e0:       mov    0x2a9a(%rip),%eax        # 404080 <g_56+0x10> first
/root/myCSmith/test/output2.c:39 (discriminator 3)
  4015e6:       mov    $0x1,%edx
func_69():
/root/myCSmith/test/output2.c:42
  4015eb:       test   %edi,%edi
  4015ed:       jne    401607 <func_65+0x27>
  4015ef:       callq  4015b0 <func_69.part.0>
func_65():
/root/myCSmith/test/output2.c:39
  4015f4:       mov    0x2a8a(%rip),%ecx        # 404084 <g_56+0x14>
  4015fa:       xor    %edx,%edx
  4015fc:       mov    0x2a7e(%rip),%eax        # 404080 <g_56+0x10> second
  401602:       test   %ecx,%ecx
  401604:       setne  %dl
/root/myCSmith/test/output2.c:39 (discriminator 6)
  401607:       cmp    %eax,%edx
  401609:       setg   %al
  40160c:       movzbl %al,%eax
  40160f:       mov    %eax,0x105b7(%rip)        # 411bcc <g>
/root/myCSmith/test/output2.c:40
  401615:       retq   
  401616:       nopw   %cs:0x0(%rax,%rax,1)
```

g_56[4] is load twice when `a` equals to 0, both on the 0x4015e0 and 0x4015fc
  • [Bug rtl-optimization/113107]... absoler at smail dot nju.edu.cn via Gcc-bugs

Reply via email to