public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113435] New: Missed optimization of loop invariant elimination
@ 2024-01-17 5:25 652023330028 at smail dot nju.edu.cn
2024-01-17 8:18 ` [Bug tree-optimization/113435] Missed optimization of loop invariant elimination: (a+b)/w rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-01-17 5:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113435
Bug ID: 113435
Summary: Missed optimization of loop invariant 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 maybe there is a missed optimization for loop invariant
elimination.
Loop invariant: (a+b)/w
https://godbolt.org/z/T6zoGxrd1
int a, b, c, d, w;
void func(){
for(int i=0;i<10000;i++){
a+=c;
b+=-c;
d+=(a+b)/w;
}
}
GCC (trunk) -O3:
func():
push rbx
mov r11d, DWORD PTR b[rip]
mov ecx, 10000
mov ebx, DWORD PTR a[rip]
mov r8d, DWORD PTR c[rip]
mov r10d, DWORD PTR w[rip]
mov r9d, DWORD PTR d[rip]
mov edi, r11d
mov esi, ebx
.L2:
lea eax, [rdi+rsi]
sub edi, r8d
add esi, r8d
cdq
idiv r10d
add r9d, eax
sub ecx, 1
jne .L2
imul eax, r8d, -9999
add ebx, r8d
sub r11d, r8d
mov DWORD PTR d[rip], r9d
sub ebx, eax
add eax, r11d
mov DWORD PTR a[rip], ebx
pop rbx
mov DWORD PTR b[rip], eax
ret
Expected code (Clang):
func(): # @func()
mov r8d, dword ptr [rip + c]
mov esi, dword ptr [rip + a]
mov edi, dword ptr [rip + b]
mov ecx, dword ptr [rip + d]
lea eax, [rdi + rsi]
cdq
idiv dword ptr [rip + w]
add eax, eax
mov edx, 10000
lea r9d, [rax + rax]
.LBB0_1: # =>This Inner Loop Header: Depth=1
add ecx, eax
add ecx, r9d
add ecx, r9d
add edx, -10
jne .LBB0_1
imul eax, r8d, 10000
add esi, eax
sub edi, eax
mov dword ptr [rip + a], esi
mov dword ptr [rip + b], edi
mov dword ptr [rip + d], ecx
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/113435] Missed optimization of loop invariant elimination: (a+b)/w
2024-01-17 5:25 [Bug tree-optimization/113435] New: Missed optimization of loop invariant elimination 652023330028 at smail dot nju.edu.cn
@ 2024-01-17 8:18 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-17 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113435
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
There's a similar bugreport, this is likely again interaction between
store-motion, re-association and invariant motion.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-01-17 8:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 5:25 [Bug tree-optimization/113435] New: Missed optimization of loop invariant elimination 652023330028 at smail dot nju.edu.cn
2024-01-17 8:18 ` [Bug tree-optimization/113435] Missed optimization of loop invariant elimination: (a+b)/w rguenth 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).