https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114972
Bug ID: 114972 Summary: [11/12/13/14/15 Regression] Missed optimization for Dead Code Elimination Product: gcc Version: 15.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. This is a regression from GCC-6.1. https://godbolt.org/z/fGzMeba66 int a, b, m; void func() { m = a + b; a++; b--; if(a+b-m != 0) m=100; //dead code } GCC -O3: func(): mov eax, DWORD PTR a[rip] mov edx, DWORD PTR b[rip] lea ecx, [rax+rdx] add eax, 1 sub edx, 1 mov DWORD PTR a[rip], eax add eax, edx cmp ecx, eax mov eax, 100 mov DWORD PTR b[rip], edx cmovne ecx, eax mov DWORD PTR m[rip], ecx ret Expected code (GCC-5.5) func(): mov edx, DWORD PTR a[rip] mov eax, DWORD PTR b[rip] lea ecx, [rdx+rax] add edx, 1 sub eax, 1 mov DWORD PTR a[rip], edx mov DWORD PTR b[rip], eax mov DWORD PTR m[rip], ecx ret Thank you very much for your time and effort! We look forward to hearing from you.