public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop
@ 2021-08-20 2:35 pinskia at gcc dot gnu.org
2021-08-20 8:45 ` [Bug tree-optimization/101991] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-20 2:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101991
Bug ID: 101991
Summary: bit_and or bit_ior with an invariant inside loop is
not pulled out of the loop
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take these two functions:
int f(int t, int d, int e)
{
int r = d;
for(int i = 0; i < t; i++)
r &= e;
return r;
}
int f1(int t, int d, int e)
{
int r = d;
if (0 < t)
r &= e;
return r;
}
They should produce the same code. Right now f still has a loop in it.
The same is true with bit_ior.
Note the code is really bad when the vectorizer comes around really.
I forgot how I found this either.
Note clang/ICC also vectorize this code crappily.
clang on the trunk almost gets there but still has a loop:
movl %esi, %eax
xorl %esi, %esi
testl %edi, %edi
cmovgl %edi, %esi
jle .LBB0_6
# %bb.1:
leal -1(%rsi), %edi
movl %esi, %ecx
andl $7, %ecx
cmpl $7, %edi
jb .LBB0_4
# %bb.2:
andl $-8, %esi
negl %esi
.p2align 4, 0x90
.LBB0_3: # =>This Inner Loop Header: Depth=1
addl $8, %esi
jne .LBB0_3
.LBB0_4:
andl %edx, %eax
testl %ecx, %ecx
je .LBB0_6
.p2align 4, 0x90
.LBB0_5: # =>This Inner Loop Header: Depth=1
addl $-1, %ecx
jne .LBB0_5
.LBB0_6:
retq
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/101991] bit_and or bit_ior with an invariant inside loop is not pulled out of the loop
2021-08-20 2:35 [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop pinskia at gcc dot gnu.org
@ 2021-08-20 8:45 ` rguenth at gcc dot gnu.org
2022-05-26 8:29 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-20 8:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101991
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2021-08-20
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
<bb 3> [local count: 955630225]:
# r_11 = PHI <r_8(6), d_3(D)(5)>
r_8 = e_7(D) & r_11;
I wonder if this is sth for phiopt to pattern match. In principle VN
would need to figure (for PRE) that the PHI translated d_3(D) & e_7(D)
is equal to r_8. So the "trick" (aka pattern-matching) could be done
during phi_translation.
But then both look like a hack. Curiously when we do
int f(int t, int d, int e)
{
int r = d & e;
for(int i = 0; i < t; i++)
r &= e;
return r;
}
aka "peel" one iteration, then CCP is what eliminates the in-loop AND.
Ah, that's because we simplify d & e & e since we optimistically start
with just the entry edge value. And that remains so. With PRE
we're not fully re-doing VN of PHIs but phi-translation seeks to
re-use existing value-numbers where possible, so a programmatic approach
doesn't work here.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/101991] bit_and or bit_ior with an invariant inside loop is not pulled out of the loop
2021-08-20 2:35 [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop pinskia at gcc dot gnu.org
2021-08-20 8:45 ` [Bug tree-optimization/101991] " rguenth at gcc dot gnu.org
@ 2022-05-26 8:29 ` pinskia at gcc dot gnu.org
2022-09-22 2:06 ` lingling.kong7 at gmail dot com
2022-10-22 22:30 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-26 8:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101991
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 105735 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/101991] bit_and or bit_ior with an invariant inside loop is not pulled out of the loop
2021-08-20 2:35 [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop pinskia at gcc dot gnu.org
2021-08-20 8:45 ` [Bug tree-optimization/101991] " rguenth at gcc dot gnu.org
2022-05-26 8:29 ` pinskia at gcc dot gnu.org
@ 2022-09-22 2:06 ` lingling.kong7 at gmail dot com
2022-10-22 22:30 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: lingling.kong7 at gmail dot com @ 2022-09-22 2:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101991
kong lingling <lingling.kong7 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lingling.kong7 at gmail dot com
--- Comment #3 from kong lingling <lingling.kong7 at gmail dot com> ---
Fixed in gcc 13.0.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/101991] bit_and or bit_ior with an invariant inside loop is not pulled out of the loop
2021-08-20 2:35 [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop pinskia at gcc dot gnu.org
` (2 preceding siblings ...)
2022-09-22 2:06 ` lingling.kong7 at gmail dot com
@ 2022-10-22 22:30 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-22 22:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101991
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
Target Milestone|--- |13.0
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-22 22:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 2:35 [Bug tree-optimization/101991] New: bit_and or bit_ior with an invariant inside loop is not pulled out of the loop pinskia at gcc dot gnu.org
2021-08-20 8:45 ` [Bug tree-optimization/101991] " rguenth at gcc dot gnu.org
2022-05-26 8:29 ` pinskia at gcc dot gnu.org
2022-09-22 2:06 ` lingling.kong7 at gmail dot com
2022-10-22 22:30 ` 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).