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

            Bug ID: 113838
           Summary: regression of redundant load operation introduced by
                    -fno-tree-forwprop introduce
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

hi, I have found for the following code, with -O2 option, gcc-10.2.0 will
generate a redundant load, and gcc-13.2.0 won't. However, with an extra flag "
-fno-tree-forwprop", gcc-13.2.0 will produce the same bad code

full code https://godbolt.org/z/objsWGnY6

```
func_37() ...

    l_50[1] = &g_51;
    if (((*l_50[1]) ^= g_26[5][3][0]))
    { /* block id: 13 */
        int32_t **l_52[5] = {&l_50[2],&l_50[2],&l_50[2],&l_50[2],&l_50[2]};
        int i;
        (*l_52[4]) = (((void*)0 != &g_51) , &g_36[3][4]);
        return p_39;
    }
    else
    { /* block id: 16 */
        int32_t *l_53 = &g_54[0][1][1];
        return l_53;
    }
```
```
func_37():
  401d74:       mov    0x364e(%rip),%edx        # 4053c8 <g_26+0x1a8>
func_11():
  401d7a:       mov    %al,0x33d9(%rip)        # 405159 <g_44+0x9>
func_37():
  401d80:       mov    0x33c2(%rip),%eax        # 405148 <g_51>
  401d86:       xor    %eax,%edx
  401d88:       cmp    0x363a(%rip),%eax        # 4053c8 <g_26+0x1a8>
  401d8e:       mov    $0x40510c,%eax
  401d93:       mov    %edx,0x33af(%rip)        # 405148 <g_51>
  401d99:       mov    $0x4051a4,%edx
  401d9e:       cmovne %rdx,%rax
```

the second load of g_26[5][3][0], i.e. "cmp    0x363a(%rip),%eax" can be
optimized away. The better code generated by gcc-13.2.0 is:
```
func_37():
  401e40:       mov    0x3582(%rip),%eax        # 4053c8 <g_26+0x1a8>
  401e46:       mov    %edx,%ecx
  401e48:       xor    %eax,%ecx
  401e4a:       cmp    %eax,%edx
  401e4c:       mov    $0x40510c,%edx
  401e51:       mov    $0x4051a4,%eax
  401e56:       cmove  %rdx,%rax
```

Reply via email to