public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114230] New: Missed optimization of loop deletion: a=0||a
@ 2024-03-05 1:04 652023330028 at smail dot nju.edu.cn
2024-03-05 1:22 ` [Bug tree-optimization/114230] Missed optimization of loop deletion: `a!=0` pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-03-05 1:04 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/114230] Missed optimization of loop deletion: `a!=0`
2024-03-05 1:04 [Bug tree-optimization/114230] New: Missed optimization of loop deletion: a=0||a 652023330028 at smail dot nju.edu.cn
@ 2024-03-05 1:22 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-05 1:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114230
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Summary|Missed optimization of loop |Missed optimization of loop
|deletion: a=0||a |deletion: `a!=0`
CC| |pinskia at gcc dot gnu.org
Keywords| |missed-optimization
Severity|normal |enhancement
Last reconfirmed| |2024-03-05
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
we have:
```
<bb 3> [local count: 1063004408]:
# i_11 = PHI <i_8(5), 0(2)>
# a_lsm.4_13 = PHI <_3(5), a_lsm.4_5(2)>
_2 = a_lsm.4_13 != 0;
_3 = (int) _2;
i_8 = i_11 + 1;
if (i_8 != 100000)
goto <bb 5>; [98.99%]
else
goto <bb 4>; [1.01%]
<bb 5> [local count: 1052266995]:
goto <bb 3>; [100.00%]
```
Which sccp does not handle `(int)a != 0` currently. It does handle `a|=b;`,
`a^=b;`, and `a&=b;` though.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-05 1:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 1:04 [Bug tree-optimization/114230] New: Missed optimization of loop deletion: a=0||a 652023330028 at smail dot nju.edu.cn
2024-03-05 1:22 ` [Bug tree-optimization/114230] Missed optimization of loop deletion: `a!=0` 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).