public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113838] New: regression of redundant load operation introduced by -fno-tree-forwprop introduce
@ 2024-02-08 17:37 absoler at smail dot nju.edu.cn
  2024-02-08 17:50 ` [Bug tree-optimization/113838] " jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-02-08 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

end of thread, other threads:[~2024-02-09  7:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 17:37 [Bug tree-optimization/113838] New: regression of redundant load operation introduced by -fno-tree-forwprop introduce absoler at smail dot nju.edu.cn
2024-02-08 17:50 ` [Bug tree-optimization/113838] " jakub at gcc dot gnu.org
2024-02-09  1:11 ` [Bug target/113838] " pinskia at gcc dot gnu.org
2024-02-09  3:37 ` absoler at smail dot nju.edu.cn
2024-02-09  3:38 ` absoler at smail dot nju.edu.cn
2024-02-09  3:39 ` absoler at smail dot nju.edu.cn
2024-02-09  7:59 ` 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).