public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/105670] New: [x86] suboptimal code for branch over two bools
@ 2022-05-20 9:49 fent at in dot tum.de
2022-05-20 18:04 ` [Bug target/105670] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: fent at in dot tum.de @ 2022-05-20 9:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105670
Bug ID: 105670
Summary: [x86] suboptimal code for branch over two bools
Product: gcc
Version: 12.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: fent at in dot tum.de
Target Milestone: ---
void test(bool a, bool b, int* t) {
if (a & b)
*t = 42;
}
With -O1, -O2, -O3, and -Os this produces:
test(bool, bool, int*):
test dil, dil
je .L1
test sil, sil
je .L1
mov DWORD PTR [rdx], 42
.L1:
ret
The following would be 5B shorter and also faster, since it minimizes branch
misses:
test(bool, bool, int*):
test sil, dil
je .L1
mov DWORD PTR [rdx], 42
.L1:
ret
Note that this is (somewhat) ABI dependent, but works on x86-64 System V,
since:
> bit 0 contains the truth value and bits 1 to 7 shall be zero
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/105670] [x86] suboptimal code for branch over two bools
2022-05-20 9:49 [Bug target/105670] New: [x86] suboptimal code for branch over two bools fent at in dot tum.de
@ 2022-05-20 18:04 ` pinskia at gcc dot gnu.org
2022-05-20 18:04 ` pinskia at gcc dot gnu.org
2023-09-17 8:33 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-20 18:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105670
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-05-20
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Gimple level is good:
_7 = a_2(D) & b_3(D);
if (_7 != 0)
goto <bb 3>; [50.00%]
else
goto <bb 4>; [50.00%]
But at expand it changes the above to:
(insn 11 10 12 (set (reg:CCZ 17 flags)
(compare:CCZ (reg/v:QI 83 [ a ])
(const_int 0 [0]))) "/app/example.cpp":2:3 -1
(nil))
(jump_insn 12 11 13 (set (pc)
(if_then_else (eq (reg:CCZ 17 flags)
(const_int 0 [0]))
(label_ref 0)
(pc))) "/app/example.cpp":2:3 -1
(int_list:REG_BR_PROB 268435460 (nil)))
(insn 13 12 14 (set (reg:CCZ 17 flags)
(compare:CCZ (reg/v:QI 85 [ b ])
(const_int 0 [0]))) "/app/example.cpp":2:3 -1
(nil))
(jump_insn 14 13 0 (set (pc)
(if_then_else (eq (reg:CCZ 17 flags)
(const_int 0 [0]))
(label_ref 0)
(pc))) "/app/example.cpp":2:3 -1
(int_list:REG_BR_PROB 357913948 (nil)))
I noticed LLVM does the same as GCC here ...
While ICC does the one test.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/105670] [x86] suboptimal code for branch over two bools
2022-05-20 9:49 [Bug target/105670] New: [x86] suboptimal code for branch over two bools fent at in dot tum.de
2022-05-20 18:04 ` [Bug target/105670] " pinskia at gcc dot gnu.org
@ 2022-05-20 18:04 ` pinskia at gcc dot gnu.org
2023-09-17 8:33 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-20 18:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105670
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/105670] [x86] suboptimal code for branch over two bools
2022-05-20 9:49 [Bug target/105670] New: [x86] suboptimal code for branch over two bools fent at in dot tum.de
2022-05-20 18:04 ` [Bug target/105670] " pinskia at gcc dot gnu.org
2022-05-20 18:04 ` pinskia at gcc dot gnu.org
@ 2023-09-17 8:33 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-17 8:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105670
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 79045.
*** This bug has been marked as a duplicate of bug 79045 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-17 8:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 9:49 [Bug target/105670] New: [x86] suboptimal code for branch over two bools fent at in dot tum.de
2022-05-20 18:04 ` [Bug target/105670] " pinskia at gcc dot gnu.org
2022-05-20 18:04 ` pinskia at gcc dot gnu.org
2023-09-17 8:33 ` 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).