public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94878] New: Failure to optimize div with bls/or pattern
@ 2020-04-30 12:15 gabravier at gmail dot com
2020-04-30 12:16 ` [Bug tree-optimization/94878] " gabravier at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 12:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94878
Bug ID: 94878
Summary: Failure to optimize div with bls/or pattern
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
unsigned y(unsigned x)
{
unsigned s = x & -x;
return s | (x % s);
}
With -O3, LLVM outputs :
y(unsigned int):
blsi ecx, edi
lea eax, [rcx - 1]
and eax, edi
or eax, ecx
ret
GCC outputs :
y(unsigned int):
mov eax, edi
xor edx, edx
blsi ecx, edi
div ecx
mov eax, edx
or eax, ecx
ret
If a single change to this function is applied, changing it to this :
unsigned y(unsigned x)
{
unsigned s = x & -x;
return x | (x % s);
}
It's equivalent to `return x`, and LLVM recognises this :
y(unsigned int):
mov eax, edi
ret
While GCC does not :
y(unsigned int):
mov eax, edi
xor edx, edx
blsi ecx, edi
div ecx
mov eax, edx
or eax, edi
ret
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/94878] Failure to optimize div with bls/or pattern
2020-04-30 12:15 [Bug tree-optimization/94878] New: Failure to optimize div with bls/or pattern gabravier at gmail dot com
@ 2020-04-30 12:16 ` gabravier at gmail dot com
2020-04-30 12:51 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 12:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94878
--- Comment #1 from Gabriel Ravier <gabravier at gmail dot com> ---
Also, the assembly outputs are for when compiling with with `-mbmi` but that
should not affect the bug itself
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/94878] Failure to optimize div with bls/or pattern
2020-04-30 12:15 [Bug tree-optimization/94878] New: Failure to optimize div with bls/or pattern gabravier at gmail dot com
2020-04-30 12:16 ` [Bug tree-optimization/94878] " gabravier at gmail dot com
@ 2020-04-30 12:51 ` rguenth at gcc dot gnu.org
2020-04-30 16:10 ` gabravier at gmail dot com
2020-04-30 19:14 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-30 12:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94878
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2020-04-30
Target| |x86_64-*-* i?86-*-*
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/94878] Failure to optimize div with bls/or pattern
2020-04-30 12:15 [Bug tree-optimization/94878] New: Failure to optimize div with bls/or pattern gabravier at gmail dot com
2020-04-30 12:16 ` [Bug tree-optimization/94878] " gabravier at gmail dot com
2020-04-30 12:51 ` rguenth at gcc dot gnu.org
@ 2020-04-30 16:10 ` gabravier at gmail dot com
2020-04-30 19:14 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-04-30 16:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94878
Gabriel Ravier <gabravier at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target|x86_64-*-* i?86-*-* |
--- Comment #3 from Gabriel Ravier <gabravier at gmail dot com> ---
I don't think this is x86-specific. Division is expensive on all processors
(except maybe 1 or two exceptions), so this should apply to all processors, and
the second transformation should apply to literally all all processors. Or do
you have confirmed that this only occurs on x86 ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/94878] Failure to optimize div with bls/or pattern
2020-04-30 12:15 [Bug tree-optimization/94878] New: Failure to optimize div with bls/or pattern gabravier at gmail dot com
` (2 preceding siblings ...)
2020-04-30 16:10 ` gabravier at gmail dot com
@ 2020-04-30 19:14 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-30 19:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94878
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-30 19:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30 12:15 [Bug tree-optimization/94878] New: Failure to optimize div with bls/or pattern gabravier at gmail dot com
2020-04-30 12:16 ` [Bug tree-optimization/94878] " gabravier at gmail dot com
2020-04-30 12:51 ` rguenth at gcc dot gnu.org
2020-04-30 16:10 ` gabravier at gmail dot com
2020-04-30 19:14 ` 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).