https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114230
Bug ID: 114230
Summary: Missed optimization of loop deletion: a=0||a
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 in the code below, looping is not necessary (the value
of 0||a doesn't change), but gcc seems to have missed this optimization.
https://godbolt.org/z/bx9jEfb63
int a;
void func(){
for(int i=0;i<100000;i++){
a=0||a;
}
}
GCC -O3:
func():
mov edx, DWORD PTR a[rip]
mov eax, 100000
.L2:
test edx, edx
setne dl
movzx edx, dl
sub eax, 1
jne .L2
mov DWORD PTR a[rip], edx
ret
Expected code (Clang):
func(): # @func()
xor eax, eax
cmp dword ptr [rip + a], 0
setne al
mov dword ptr [rip + a], eax
ret
Thank you very much for your time and effort! We look forward to hearing from
you.