public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114782] New: [Regression] Missed optimization of Induction Variable
@ 2024-04-19 15:01 652023330028 at smail dot nju.edu.cn
2024-04-19 17:59 ` [Bug target/114782] " pinskia at gcc dot gnu.org
2024-04-19 18:07 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-04-19 15:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114782
Bug ID: 114782
Summary: [Regression] Missed optimization of Induction Variable
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 for the following code, GCC may have missed an
optimization of inductive variables ('x'). It may be a regression from
gcc-4.8.1.
https://godbolt.org/z/je9sjzPj6
int a,b;
void func(int x){
for(int i=0;i<b;i++){
x=i*5;
a+=x;
b--;
}
}
GCC-trunk -O3:
func(int):
mov edx, DWORD PTR b[rip]
test edx, edx
jle .L1
mov ecx, DWORD PTR a[rip]
xor eax, eax
.L3:
lea esi, [rax+rax*4]
sub edx, 1
add eax, 1
add ecx, esi
cmp edx, eax
jg .L3
mov DWORD PTR a[rip], ecx
mov DWORD PTR b[rip], edx
.L1:
ret
Expected code:
GCC-4.7.4 -O3:
func(int):
mov esi, DWORD PTR b[rip]
test esi, esi
jle .L1
mov ecx, DWORD PTR a[rip]
lea edi, [rsi-1]
xor edx, edx
xor eax, eax
.L3:
mov esi, edi
add ecx, edx
add edx, 5
sub esi, eax
add eax, 1
cmp eax, esi
jl .L3
mov DWORD PTR a[rip], ecx
mov DWORD PTR b[rip], esi
.L1:
rep
ret
Thank you very much for your time and effort! We look forward to hearing from
you.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/114782] [Regression] Missed optimization of Induction Variable
2024-04-19 15:01 [Bug tree-optimization/114782] New: [Regression] Missed optimization of Induction Variable 652023330028 at smail dot nju.edu.cn
@ 2024-04-19 17:59 ` pinskia at gcc dot gnu.org
2024-04-19 18:07 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-19 17:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114782
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Target| |x86_64-linux-gnu
Status|UNCONFIRMED |RESOLVED
Component|tree-optimization |target
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
so it depends on the cost model of lea performance; which itself is a mess.
Anyways it is a dup of bug 90088.
*** This bug has been marked as a duplicate of bug 90088 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/114782] [Regression] Missed optimization of Induction Variable
2024-04-19 15:01 [Bug tree-optimization/114782] New: [Regression] Missed optimization of Induction Variable 652023330028 at smail dot nju.edu.cn
2024-04-19 17:59 ` [Bug target/114782] " pinskia at gcc dot gnu.org
@ 2024-04-19 18:07 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-19 18:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114782
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I should note I tested aarch64 (where lea 3 operand instructions are still
cheap) and powerpc (where lea like instructions don't exist) and they produce
what I expect, aarch64 produces an lea like instruction while powerpc produces
no shifts/multiplies for the loop.
PowerPC:
.L3:
addi 9,9,-1
add 8,8,10
subf 7,9,6
addi 10,10,5
cmpw 0,9,7
bgt 0,.L3
aarch64 (default tuning):
.L3:
add w3, w0, w0, lsl 2
sub w1, w1, #1
add w0, w0, 1
add w2, w2, w3
cmp w1, w0
bgt .L3
aarch64 (thunderxt99 tuning):
.L3:
sub w0, w0, #1
add w2, w2, w1
add w1, w1, 5
sub w3, w4, w0
cmp w0, w3
bgt .L3
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-19 18:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-19 15:01 [Bug tree-optimization/114782] New: [Regression] Missed optimization of Induction Variable 652023330028 at smail dot nju.edu.cn
2024-04-19 17:59 ` [Bug target/114782] " pinskia at gcc dot gnu.org
2024-04-19 18:07 ` 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).