public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114145] New: Missed optimization of loop deletion
@ 2024-02-28 9:22 652023330028 at smail dot nju.edu.cn
2024-02-28 10:31 ` [Bug tree-optimization/114145] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-02-28 9:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114145
Bug ID: 114145
Summary: Missed optimization of loop deletion
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, but gcc
seems to have missed this optimization.
https://godbolt.org/z/sYqzh8M3c
int a, b;
void func(int c){
for(int i=0;i<700;i++){
b=c;
c=a;
}
}
GCC -O3:
func(int):
mov edx, DWORD PTR a[rip]
mov eax, 700
jmp .L2
.L3:
sub eax, 3
mov edi, edx
.L2:
cmp eax, 1
jne .L3
mov DWORD PTR b[rip], edi
ret
Expected code (Clang):
func(int): # @func(int)
mov eax, dword ptr [rip + a]
mov dword ptr [rip + b], eax
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/114145] Missed optimization of loop deletion
2024-02-28 9:22 [Bug tree-optimization/114145] New: Missed optimization of loop deletion 652023330028 at smail dot nju.edu.cn
@ 2024-02-28 10:31 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-02-28 10:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114145
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-02-28
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Store motion turns this into
<bb 2> [local count: 10737416]:
b_lsm.3_3 = _15(D);
c_7 = a;
<bb 3> [local count: 1063004408]:
# c_12 = PHI <c_7(5), c_4(D)(2)>
# i_13 = PHI <i_8(5), 0(2)>
b_lsm.3_2 = c_12;
i_8 = i_13 + 1;
if (i_8 != 700)
goto <bb 5>; [98.99%]
else
goto <bb 4>; [1.01%]
<bb 5> [local count: 1052266995]:
goto <bb 3>; [100.00%]
<bb 4> [local count: 10737416]:
# b_lsm.3_11 = PHI <b_lsm.3_2(3)>
b = b_lsm.3_11;
return;
where ultimatively final value replacement fails because SCEV fails here:
(analyze_scalar_evolution
(loop_nb = 1)
(scalar = c_7)
(get_scalar_evolution
(scalar = c_7)
(scalar_evolution = ))
)
(instantiate_scev
(instantiate_below = 2 -> 3)
(evolution_loop = 1)
(chrec = c_7)
(res = c_7))
(evolution_function = scev_not_known))
indeed there's no way to express the evolution of this induction variable
which has just two values. Might be a simple thing to special case
in final value replacement though. There we see just
<bb 3> [local count: 1063004408]:
# c_12 = PHI <c_7(5), c_4(D)(2)>
...
<bb 4> [local count: 10737416]:
# c_9 = PHI <c_12(3)>
so the final value is niter == 0 ? c_4(D) : c_7.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-28 10:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 9:22 [Bug tree-optimization/114145] New: Missed optimization of loop deletion 652023330028 at smail dot nju.edu.cn
2024-02-28 10:31 ` [Bug tree-optimization/114145] " 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).