public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/98567] New: Failure to optimize using ZF flag from blsi
@ 2021-01-06 16:32 gabravier at gmail dot com
2021-01-06 16:48 ` [Bug target/98567] " jakub at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: gabravier at gmail dot com @ 2021-01-06 16:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98567
Bug ID: 98567
Summary: Failure to optimize using ZF flag from blsi
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
bool f(__UINT64_TYPE__ x)
{
return (-x & x) == 0;
}
With -O3 -mbmi, LLVM compiles this to:
f:
blsi rax, rdi
sete al
ret
GCC compiles this to:
f:
blsi rdi, rdi
test rdi, rdi
sete al
ret
The usage of `test` can be entirely removed, as `blsi` already sets ZF
accordingly.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/98567] Failure to optimize using ZF flag from blsi
2021-01-06 16:32 [Bug target/98567] New: Failure to optimize using ZF flag from blsi gabravier at gmail dot com
@ 2021-01-06 16:48 ` jakub at gcc dot gnu.org
2021-01-06 16:58 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-06 16:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98567
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
CC| |jakub at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2021-01-06
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/98567] Failure to optimize using ZF flag from blsi
2021-01-06 16:32 [Bug target/98567] New: Failure to optimize using ZF flag from blsi gabravier at gmail dot com
2021-01-06 16:48 ` [Bug target/98567] " jakub at gcc dot gnu.org
@ 2021-01-06 16:58 ` jakub at gcc dot gnu.org
2021-01-06 18:55 ` ubizjak at gmail dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-06 16:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98567
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49901
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49901&action=edit
gcc11-pr98567.patch
Untested fix.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/98567] Failure to optimize using ZF flag from blsi
2021-01-06 16:32 [Bug target/98567] New: Failure to optimize using ZF flag from blsi gabravier at gmail dot com
2021-01-06 16:48 ` [Bug target/98567] " jakub at gcc dot gnu.org
2021-01-06 16:58 ` jakub at gcc dot gnu.org
@ 2021-01-06 18:55 ` ubizjak at gmail dot com
2021-01-07 16:20 ` cvs-commit at gcc dot gnu.org
2021-01-07 16:22 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2021-01-06 18:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98567
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
Comment on attachment 49901
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49901
gcc11-pr98567.patch
>+(define_insn "*bmi_blsi_<mode>_cmp"
>+ [(set (reg:CCZ FLAGS_REG)
>+ (compare:CCZ
>+ (and:SWI48
>+ (neg:SWI48 (match_operand:SWI48 1 "nonimmediate_operand" "rm"))
>+ (match_dup 1))
>+ (const_int 0)))
>+ (set (match_operand:SWI48 0 "register_operand" "=r")
>+ (and:SWI48 (neg:SWI48 (match_dup 1)) (match_dup 1)))]
>+ "TARGET_BMI"
>+ "blsi\t{%1, %0|%0, %1}"
>+ [(set_attr "type" "bitmanip")
>+ (set_attr "btver2_decode" "double")
>+ (set_attr "mode" "<MODE>")])
This insn also sets SF and thus can handle all CCNOmode comparisons. So,
ix86_match_ccmode (insn, CCNOmode) insn predicate should be used instead of CCZ
mode.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/98567] Failure to optimize using ZF flag from blsi
2021-01-06 16:32 [Bug target/98567] New: Failure to optimize using ZF flag from blsi gabravier at gmail dot com
` (2 preceding siblings ...)
2021-01-06 18:55 ` ubizjak at gmail dot com
@ 2021-01-07 16:20 ` cvs-commit at gcc dot gnu.org
2021-01-07 16:22 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-07 16:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98567
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:6bca2ebf10654b8beb5c5737c8652e8262901294
commit r11-6520-g6bca2ebf10654b8beb5c5737c8652e8262901294
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Jan 7 17:18:58 2021 +0100
i386: Optimize blsi followed by comparison [PR98567]
The BLSI instruction sets SF and ZF based on the result and clears OF.
CF is set to something unrelated.
The following patch optimizes BLSI followed by comparison, so we don't need
to emit a TEST insn in between.
2021-01-07 Jakub Jelinek <jakub@redhat.com>
PR target/98567
* config/i386/i386.md (*bmi_blsi_<mode>_cmp,
*bmi_blsi_<mode>_ccno):
New define_insn patterns.
* gcc.target/i386/pr98567-1.c: New test.
* gcc.target/i386/pr98567-2.c: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/98567] Failure to optimize using ZF flag from blsi
2021-01-06 16:32 [Bug target/98567] New: Failure to optimize using ZF flag from blsi gabravier at gmail dot com
` (3 preceding siblings ...)
2021-01-07 16:20 ` cvs-commit at gcc dot gnu.org
@ 2021-01-07 16:22 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-07 16:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98567
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-07 16:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 16:32 [Bug target/98567] New: Failure to optimize using ZF flag from blsi gabravier at gmail dot com
2021-01-06 16:48 ` [Bug target/98567] " jakub at gcc dot gnu.org
2021-01-06 16:58 ` jakub at gcc dot gnu.org
2021-01-06 18:55 ` ubizjak at gmail dot com
2021-01-07 16:20 ` cvs-commit at gcc dot gnu.org
2021-01-07 16:22 ` jakub 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).