public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz
@ 2021-02-03 20:58 gabravier at gmail dot com
2021-02-04 8:10 ` [Bug rtl-optimization/98961] " rguenth at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2021-02-03 20:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
Bug ID: 98961
Summary: Failure to optimize successive comparisons with 0 into
clz
Product: gcc
Version: 11.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: ---
int f(int i, int j)
{
return i == 0 || j == 0;
}
This can be optimized to `return (__builtin_clz(i) | __builtin_clz(j)) >> 5;`
(if `clz(0)` returns 0). LLVM does this transformation, but GCC does not.
On x86, for example, with lzcnt, while this does not seem to be a net win in
terms of performance (at least, not for this code alone), it also simply not a
loss. As it is a win in terms of code size (which should make it a net win in
most situations), I think that should make it a net win overall in actual code.
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10588
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/98961] Failure to optimize successive comparisons with 0 into clz
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
@ 2021-02-04 8:10 ` rguenth at gcc dot gnu.org
2021-02-04 12:01 ` ubizjak at gmail dot com
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-02-04 8:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|tree-optimization |rtl-optimization
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
IMHO this is more for RTL.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/98961] Failure to optimize successive comparisons with 0 into clz
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
2021-02-04 8:10 ` [Bug rtl-optimization/98961] " rguenth at gcc dot gnu.org
@ 2021-02-04 12:01 ` ubizjak at gmail dot com
2021-02-04 12:08 ` ubizjak at gmail dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2021-02-04 12:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ubizjak at gmail dot com
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 50124
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50124&action=edit
Experimental x86 patch
Experimental patch for x86 target.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/98961] Failure to optimize successive comparisons with 0 into clz
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
2021-02-04 8:10 ` [Bug rtl-optimization/98961] " rguenth at gcc dot gnu.org
2021-02-04 12:01 ` ubizjak at gmail dot com
@ 2021-02-04 12:08 ` ubizjak at gmail dot com
2021-07-19 16:03 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: ubizjak at gmail dot com @ 2021-02-04 12:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
Please note that LZCNT insn has it own set of problems (e.g.
TARGET_AVOID_FALSE_DEP_FOR_BMI), so I'm not convinced that even:
int z (int i)
{
return i == 0;
}
benefits from using LZCNT:
0: 31 c0 xor %eax,%eax
2: f3 0f bd c7 lzcnt %edi,%eax
6: c1 e8 05 shr $0x5,%eax
9: c3 retq
vs:
0: 31 c0 xor %eax,%eax
2: 85 ff test %edi,%edi
4: 0f 94 c0 sete %al
7: c3 retq
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/98961] Failure to optimize successive comparisons with 0 into clz
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
` (2 preceding siblings ...)
2021-02-04 12:08 ` ubizjak at gmail dot com
@ 2021-07-19 16:03 ` pinskia at gcc dot gnu.org
2023-05-20 1:51 ` [Bug middle-end/98961] " pinskia at gcc dot gnu.org
2023-05-20 1:51 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-19 16:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/98961] Failure to optimize successive comparisons with 0 into clz
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
` (3 preceding siblings ...)
2021-07-19 16:03 ` pinskia at gcc dot gnu.org
@ 2023-05-20 1:51 ` pinskia at gcc dot gnu.org
2023-05-20 1:51 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-20 1:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Component|rtl-optimization |middle-end
Last reconfirmed| |2023-05-20
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, I think this should happen at expand time and only if the target
does not have conditional compares (e.g. like aarch64).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/98961] Failure to optimize successive comparisons with 0 into clz
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
` (4 preceding siblings ...)
2023-05-20 1:51 ` [Bug middle-end/98961] " pinskia at gcc dot gnu.org
@ 2023-05-20 1:51 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-20 1:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
or could be a cost thing ...
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-05-20 1:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 20:58 [Bug tree-optimization/98961] New: Failure to optimize successive comparisons with 0 into clz gabravier at gmail dot com
2021-02-04 8:10 ` [Bug rtl-optimization/98961] " rguenth at gcc dot gnu.org
2021-02-04 12:01 ` ubizjak at gmail dot com
2021-02-04 12:08 ` ubizjak at gmail dot com
2021-07-19 16:03 ` pinskia at gcc dot gnu.org
2023-05-20 1:51 ` [Bug middle-end/98961] " pinskia at gcc dot gnu.org
2023-05-20 1:51 ` 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).