public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114508] New: Missed optimization of Dead Code Elimination
@ 2024-03-28  5:54 652023330028 at smail dot nju.edu.cn
  2024-03-28  6:00 ` [Bug tree-optimization/114508] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-03-28  5:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114508
           Summary: Missed optimization of Dead Code Elimination
           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 noticed that the code below can be optimized by Dead Code
Elimination, but gcc -O3 missed it.

Reduced code:
https://godbolt.org/z/j9a3Mza3d

int a, b;
void func(int g, int d){
    int x=g+d;
    if(x>0){
        d--;
        int t=g+d;
        if(t<0){  //false
            b=1;  //dead code
        }
    }
}

GCC -O3:
func(int, int):
        lea     eax, [rdi+rsi]
        test    eax, eax
        jle     .L1
        lea     eax, [rdi-1+rsi]
        test    eax, eax
        js      .L4
.L1:
        ret
.L4:
        mov     DWORD PTR b[rip], 1
        ret

Expected code (Clang):
func(int, int):                              # @func(int, int)
        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/114508] Missed optimization of Dead Code Elimination
  2024-03-28  5:54 [Bug tree-optimization/114508] New: Missed optimization of Dead Code Elimination 652023330028 at smail dot nju.edu.cn
@ 2024-03-28  6:00 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-28  6:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It comes down to figuring out that t is `x - 1`.

The problem is GCC does not reassociate signed types for overflow reasons.

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

end of thread, other threads:[~2024-03-28  6:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28  5:54 [Bug tree-optimization/114508] New: Missed optimization of Dead Code Elimination 652023330028 at smail dot nju.edu.cn
2024-03-28  6:00 ` [Bug tree-optimization/114508] " 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).