public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests
@ 2021-04-05 20:15 msebor at gcc dot gnu.org
2021-04-05 20:22 ` [Bug tree-optimization/99918] " pinskia at gcc dot gnu.org
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-05 20:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Bug ID: 99918
Summary: suboptimal code for bool bitfield tests
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC does a better job folding operations involving plain Booleans than it does
with bool bit-fields. The example below shows that in f() the return statement
is folded to zero while in g() it's not. This is behind a class of
-Wmaybe-uninitialized warnings.
$ cat z.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout z.c
struct A { _Bool i, j; };
_Bool f (struct A a)
{
if (a.i)
a.j = 0;
else
a.j = a.i;
return a.j; // folded to 0
}
struct B { _Bool i: 1, j: 1; };
_Bool g (struct B b)
{
if (b.i)
b.j = 0;
else
b.j = b.i;
return b.j; // not folded
}
;; Function f (f, funcdef_no=0, decl_uid=1946, cgraph_uid=1, symbol_order=0)
_Bool f (struct A a)
{
<bb 2> [local count: 1073741824]:
return 0;
}
;; Function g (g, funcdef_no=1, decl_uid=1953, cgraph_uid=2, symbol_order=1)
Removing basic block 5
_Bool g (struct B b)
{
_Bool b$j;
unsigned char _1;
unsigned char _2;
_Bool _3;
<bb 2> [local count: 1073741824]:
_1 = VIEW_CONVERT_EXPR<unsigned char>(b);
_2 = _1 & 1;
if (_2 != 0)
goto <bb 4>; [50.00%]
else
goto <bb 3>; [50.00%]
<bb 3> [local count: 536870913]:
_3 = b.i;
<bb 4> [local count: 1073741824]:
# b$j_5 = PHI <0(2), _3(3)>
return b$j_5;
}
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
@ 2021-04-05 20:22 ` pinskia at gcc dot gnu.org
2021-04-05 20:23 ` [Bug tree-optimization/99918] [9/10/11 Regression] " msebor at gcc dot gnu.org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-04-05 20:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This comes down to lowering bitfields too soon.
my bet it will happen even integer bitfields will have a problem.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [9/10/11 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
2021-04-05 20:22 ` [Bug tree-optimization/99918] " pinskia at gcc dot gnu.org
@ 2021-04-05 20:23 ` msebor at gcc dot gnu.org
2021-04-05 20:27 ` msebor at gcc dot gnu.org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-05 20:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.2.0, 11.0, 6.3.0, 7.0.1,
| |8.3.0, 9.3.0
Summary|suboptimal code for bool |[9/10/11 Regression]
|bitfield tests |suboptimal code for bool
| |bitfield tests
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Bisection points to r225825 as the revision where GCC started to fail to fold
the code in g().
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [9/10/11 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
2021-04-05 20:22 ` [Bug tree-optimization/99918] " pinskia at gcc dot gnu.org
2021-04-05 20:23 ` [Bug tree-optimization/99918] [9/10/11 Regression] " msebor at gcc dot gnu.org
@ 2021-04-05 20:27 ` msebor at gcc dot gnu.org
2021-04-05 20:40 ` msebor at gcc dot gnu.org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-05 20:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
This only seems to affect C _Bool bit-fields and not C++ bool.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [9/10/11 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (2 preceding siblings ...)
2021-04-05 20:27 ` msebor at gcc dot gnu.org
@ 2021-04-05 20:40 ` msebor at gcc dot gnu.org
2021-04-06 8:39 ` rguenth at gcc dot gnu.org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-04-05 20:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> This comes down to lowering bitfields too soon.
> my bet it will happen even integer bitfields will have a problem.
Yes, unsigned bit-fields suffer the same problem but unlike for _Bool, GCC
never emitted optimal code for those for this test case.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [9/10/11 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (3 preceding siblings ...)
2021-04-05 20:40 ` msebor at gcc dot gnu.org
@ 2021-04-06 8:39 ` rguenth at gcc dot gnu.org
2021-04-08 14:22 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-06 8:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2021-04-06
Blocks| |85316
Ever confirmed|0 |1
Target Milestone|--- |9.4
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The main issue is optimize_bit_field_compare in fold-const.c which produces
during GENERIC folding in .005t.original:
if ((BIT_FIELD_REF <b, 8, 0> & 1) != 0)
{
b.j = 0;
}
else
{
b.j = b.i;
}
return b.j;
that's premature in this place. For f() it also takes until DOM3 to do
the folding unless you disable SRA which then makes EVRP recognize the
second store as a.j = 0. With SRA we fail to derive ranges for a_10 in
a_10 = MEM <unsigned char> [(struct A *)&a];
a$1_11 = MEM <unsigned char> [(struct A *)&a + 1B];
_1 = VIEW_CONVERT_EXPR<_Bool>(a_10);
if (_1 != 0)
goto <bb 4>; [INV]
else
goto <bb 3>; [INV]
<bb 3> :
<bb 4> :
# a$1_9 = PHI <0(2), a_10(3)>
_7 = VIEW_CONVERT_EXPR<_Bool>(a$1_9);
thus we're missing looking through VIEW_CONVERT_EXPR in register_assert_for.
Amending that would eventually also allow optimizing the prematurely folded
vairant.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [9/10/11 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (4 preceding siblings ...)
2021-04-06 8:39 ` rguenth at gcc dot gnu.org
@ 2021-04-08 14:22 ` rguenth at gcc dot gnu.org
2021-06-01 8:20 ` [Bug tree-optimization/99918] [9/10/11/12 " rguenth at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-08 14:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [9/10/11/12 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (5 preceding siblings ...)
2021-04-08 14:22 ` rguenth at gcc dot gnu.org
@ 2021-06-01 8:20 ` rguenth at gcc dot gnu.org
2022-05-27 9:44 ` [Bug tree-optimization/99918] [10/11/12/13 " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.4 |9.5
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [10/11/12/13 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (6 preceding siblings ...)
2021-06-01 8:20 ` [Bug tree-optimization/99918] [9/10/11/12 " rguenth at gcc dot gnu.org
@ 2022-05-27 9:44 ` rguenth at gcc dot gnu.org
2022-06-28 10:44 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27 9:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.5 |10.4
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [10/11/12/13 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (7 preceding siblings ...)
2022-05-27 9:44 ` [Bug tree-optimization/99918] [10/11/12/13 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:44 ` jakub at gcc dot gnu.org
2022-07-01 12:49 ` fkorta at gmail dot com
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.4 |10.5
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [10/11/12/13 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (8 preceding siblings ...)
2022-06-28 10:44 ` jakub at gcc dot gnu.org
@ 2022-07-01 12:49 ` fkorta at gmail dot com
2023-07-07 10:39 ` [Bug tree-optimization/99918] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-12 22:05 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: fkorta at gmail dot com @ 2022-07-01 12:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Franek Korta <fkorta at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |fkorta at gmail dot com
--- Comment #9 from Franek Korta <fkorta at gmail dot com> ---
Another simple example:
#include <cstdint>
struct SomeClass {
bool cfg1 : 1;
bool cfg2 : 1;
bool cfg3 : 1;
bool check() const noexcept { return cfg1 || cfg2 || cfg3; }
};
bool check(const SomeClass& rt) {
return rt.check();
}
Emits:
check(SomeClass const&):
movzx edx, BYTE PTR [rdi]
mov eax, edx
and eax, 1
jne .L1
mov eax, edx
shr al
and eax, 1
je .L4
.L1:
ret
.L4:
mov eax, edx
shr al, 2
and eax, 1
ret
While it should:
check(SomeClass const&):
test byte ptr [rdi], 7
setne al
ret
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [11/12/13/14 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (9 preceding siblings ...)
2022-07-01 12:49 ` fkorta at gmail dot com
@ 2023-07-07 10:39 ` rguenth at gcc dot gnu.org
2023-07-12 22:05 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.5 |11.5
--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/99918] [11/12/13/14 Regression] suboptimal code for bool bitfield tests
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
` (10 preceding siblings ...)
2023-07-07 10:39 ` [Bug tree-optimization/99918] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2023-07-12 22:05 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-12 22:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99918
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #2)
> Bisection points to r225825 as the revision where GCC started to fail to
> fold the code in g().
the fold-const didn't check `types_match (type, TREE_TYPE (@0))` but rather
just did the equivalent to:
(simplify
(ne @0 integer_zerop@1)
(if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE)
(non_lvalue (convert @0))))
While match now does not do the convert and checks the types_match check
instead.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-07-12 22:05 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-05 20:15 [Bug tree-optimization/99918] New: suboptimal code for bool bitfield tests msebor at gcc dot gnu.org
2021-04-05 20:22 ` [Bug tree-optimization/99918] " pinskia at gcc dot gnu.org
2021-04-05 20:23 ` [Bug tree-optimization/99918] [9/10/11 Regression] " msebor at gcc dot gnu.org
2021-04-05 20:27 ` msebor at gcc dot gnu.org
2021-04-05 20:40 ` msebor at gcc dot gnu.org
2021-04-06 8:39 ` rguenth at gcc dot gnu.org
2021-04-08 14:22 ` rguenth at gcc dot gnu.org
2021-06-01 8:20 ` [Bug tree-optimization/99918] [9/10/11/12 " rguenth at gcc dot gnu.org
2022-05-27 9:44 ` [Bug tree-optimization/99918] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:44 ` jakub at gcc dot gnu.org
2022-07-01 12:49 ` fkorta at gmail dot com
2023-07-07 10:39 ` [Bug tree-optimization/99918] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-12 22:05 ` 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).