public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111562] New: Missed optimization when the value of another variable can be used directly
@ 2023-09-24  3:40 652023330028 at smail dot nju.edu.cn
  2023-09-24  3:43 ` [Bug tree-optimization/111562] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2023-09-24  3:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111562
           Summary: Missed optimization when the value of another variable
                    can be used directly
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, we found some optimizations that GCC may have missed. We would greatly
appreicate if you can take a look and let us know what you think.

Example 1:
https://godbolt.org/z/nPW7j1xvq

Given the following code: 
```c++
int var22=0;
int var23=0;
void test(int var7, int var9, int var11, int var12) {
    var22 = var12 + var9 + var11;
    var23 = var12 + (var9 + var7 + var11);
}
```

In fact, `var23` can be directly optimized to `var22+var7`, but gcc-trunk -O3
does not:
```asm
test(int, int, int, int):
        lea     eax, [rcx+rsi]
        add     esi, edi
        add     esi, edx
        add     eax, edx
        add     esi, ecx
        mov     DWORD PTR var22[rip], eax
        mov     DWORD PTR var23[rip], esi
        ret
var23:
        .zero   4
var22:
        .zero   4
```

Example 2:
https://godbolt.org/z/8vE69WPc7

Given the following code: 
```c++
extern int var_15;
extern int var_16;
void test(int var_2, int var_3, int var_4, int var_6, int var_9) {
    var_15 = var_9 - (var_2 + var_6 + var_3 + var_4);
    var_16 = var_4 + var_6 + var_2;
}
```

By adjusting the calculation order, the `var_16` calculation can actually use
the intermediate result of the `var_15` calculation process directly, but
gcc-trunk -O3 does not:
```asm
test(int, int, int, int, int):
        lea     eax, [rdi+rcx]
        add     ecx, edx
        add     eax, esi
        add     ecx, edi
        add     eax, edx
        mov     DWORD PTR var_16[rip], ecx
        sub     r8d, eax
        mov     DWORD PTR var_15[rip], r8d
        ret
```

Thank you very much for your time and effort! We look forward to hearing from
you.

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

* [Bug tree-optimization/111562] Missed optimization when the value of another variable can be used directly
  2023-09-24  3:40 [Bug tree-optimization/111562] New: Missed optimization when the value of another variable can be used directly 652023330028 at smail dot nju.edu.cn
@ 2023-09-24  3:43 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-24  3:43 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Same issue as PR 111560 .

*** This bug has been marked as a duplicate of bug 111560 ***

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

end of thread, other threads:[~2023-09-24  3:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-24  3:40 [Bug tree-optimization/111562] New: Missed optimization when the value of another variable can be used directly 652023330028 at smail dot nju.edu.cn
2023-09-24  3:43 ` [Bug tree-optimization/111562] " pinskia 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).