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.
  • [Bug tree-optimization/1... 652023330028 at smail dot nju.edu.cn via Gcc-bugs

Reply via email to