public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112277] New: Missed optimization of loop deletion because of missed loopUnswitch and useless instruction elimination
@ 2023-10-29 15:45 652023330028 at smail dot nju.edu.cn
2023-10-29 16:26 ` [Bug tree-optimization/112277] " pinskia at gcc dot gnu.org
2023-10-30 14:00 ` rguenth at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2023-10-29 15:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112277
Bug ID: 112277
Summary: Missed optimization of loop deletion because of missed
loopUnswitch and useless instruction 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 the loop in the code below is not necessary. But GCC
misses this loop deletion optimization, probably because of the missing in loop
Unswitch and useless instruction elimination annotated below.
https://godbolt.org/z/vMPGnhc9n
int b, c;
int n;
void test() {
for (int i = 0; i < 1000; i += b) {
if(c < 0){
c = n;
}
}
}
GCC -O3:
test():
mov ecx, DWORD PTR c[rip]
mov edi, DWORD PTR n[rip]
xor esi, esi
xor eax, eax
mov edx, DWORD PTR b[rip]
test ecx, ecx
jns .L3
.L2: #Loop
add eax, edx
mov esi, 1
mov ecx, edi #Loop invariants: edi
cmp eax, 999
jg .L13
test ecx, ecx #Loop invariants: ecx
js .L2 #Missed LoopUnswitch
.L3: #Useless instructions
add eax, edx
cmp eax, 999
jle .L3 #Useless instructions
test sil, sil
je .L1
.L13:
mov DWORD PTR c[rip], ecx
.L1:
ret
Expected code:
test():
mov eax, DWORD PTR c[rip]
test eax, eax
js .L4
ret
.L4:
mov eax, DWORD PTR n[rip]
mov DWORD PTR c[rip], eax
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 tree-optimization/112277] Missed optimization of loop deletion because of missed loopUnswitch and useless instruction elimination
2023-10-29 15:45 [Bug tree-optimization/112277] New: Missed optimization of loop deletion because of missed loopUnswitch and useless instruction elimination 652023330028 at smail dot nju.edu.cn
@ 2023-10-29 16:26 ` pinskia at gcc dot gnu.org
2023-10-30 14:00 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-29 16:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112277
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |missed-optimization
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/112277] Missed optimization of loop deletion because of missed loopUnswitch and useless instruction elimination
2023-10-29 15:45 [Bug tree-optimization/112277] New: Missed optimization of loop deletion because of missed loopUnswitch and useless instruction elimination 652023330028 at smail dot nju.edu.cn
2023-10-29 16:26 ` [Bug tree-optimization/112277] " pinskia at gcc dot gnu.org
@ 2023-10-30 14:00 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-30 14:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112277
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hubicka at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2023-10-30
Status|UNCONFIRMED |NEW
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. This seems to be a limit of loop splitting which should handle this
situation but is hindered by us having only a single forwarder from the
branch (on the false edge). It only considers "edges" where it has a block
that only executes on the path which makes it not try "both" directions here
and fail. (get_cond_invariant_branch, branch_removable_p and the dominance
check)
if (c_lsm.6_6 < 0)
goto <bb 5>; [41.00%]
else
goto <bb 4>; [59.00%]
<bb 4> [local count: 563821836]:
<bb 5> [local count: 955630226]:
# c_lsm.6_4 = PHI <c_lsm.6_6(4), n.1_2(3)>
# c_lsm_flag.7_10 = PHI <c_lsm_flag.7_11(4), 1(3)>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-30 14:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-29 15:45 [Bug tree-optimization/112277] New: Missed optimization of loop deletion because of missed loopUnswitch and useless instruction elimination 652023330028 at smail dot nju.edu.cn
2023-10-29 16:26 ` [Bug tree-optimization/112277] " pinskia at gcc dot gnu.org
2023-10-30 14:00 ` 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).