public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
[parent not found: <bug-15826-5009@http.gcc.gnu.org/bugzilla/>]
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
[not found] <bug-15826-5009@http.gcc.gnu.org/bugzilla/>
@ 2006-03-02 14:24 ` pinskia at gcc dot gnu dot org
2007-04-05 21:01 ` steven at gcc dot gnu dot org
2008-04-30 19:22 ` rguenth at gcc dot gnu dot org
2 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-02 14:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2006-03-02 14:24 -------
This is interesting, we now get BIT_FIELD_REF.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
[not found] <bug-15826-5009@http.gcc.gnu.org/bugzilla/>
2006-03-02 14:24 ` pinskia at gcc dot gnu dot org
@ 2007-04-05 21:01 ` steven at gcc dot gnu dot org
2008-04-30 19:22 ` rguenth at gcc dot gnu dot org
2 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2007-04-05 21:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from steven at gcc dot gnu dot org 2007-04-05 22:01 -------
The tree dump for the original test case now looks like this for me:
;; Function foo (foo)
foo (p)
{
<bb 2>:
return (unsigned int) ((BIT_FIELD_REF <*p, 8, 0> & 1) != 0);
}
;; Function bar (bar)
bar (p)
{
<bb 2>:
return (unsigned int) p->bit;
}
The resulting assembler output is the same, but I imagine VRP should be able to
fold away the "& 1" test. I don't know if the BIT_FIELD_REF itself should be
optimized away, but I guess so. Consider the following test case:
struct s
{
unsigned int bit:1;
};
unsigned int
foo (struct s *p)
{
if (p->bit)
return (unsigned int) (p->bit);
else
return 0;
}
This gets "optimized" at the tree level to this ugly code:
;; Function foo (foo)
foo (p)
{
unsigned int D.1979;
<bb 2>:
if ((BIT_FIELD_REF <*p, 8, 0> & 1) != 0) goto <L0>; else goto <L4>;
<L4>:;
D.1979 = 0;
goto <bb 5> (<L2>);
<L0>:;
D.1979 = (unsigned int) p->bit;
<L2>:;
return D.1979;
}
In summary, I don't think we can close this bug just yet.
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2005-12-10 04:15:46 |2007-04-05 22:01:25
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
[not found] <bug-15826-5009@http.gcc.gnu.org/bugzilla/>
2006-03-02 14:24 ` pinskia at gcc dot gnu dot org
2007-04-05 21:01 ` steven at gcc dot gnu dot org
@ 2008-04-30 19:22 ` rguenth at gcc dot gnu dot org
2 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-04-30 19:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from rguenth at gcc dot gnu dot org 2008-04-30 19:21 -------
On the trunk I have after phiopt1:
;; Function andrew (andrew)
Removing basic block 3
Merging blocks 2 and 4
andrew (struct s * p)
{
_Bool D.1212;
int i;
unsigned int D.1183;
<unnamed-unsigned:1> D.1182;
<bb 2>:
D.1182_3 = p_2(D)->bit;
(void) 0;
D.1212_9 = D.1182_3 != 0;
i_10 = (int) D.1212_9;
D.1183_6 = (unsigned int) i_10;
return D.1183_6;
}
;; Function foo (foo)
Removing basic block 3
Merging blocks 2 and 4
foo (struct s * p)
{
_Bool D.1199;
unsigned int D.1177;
<unnamed-unsigned:1> D.1176;
<bb 2>:
D.1176_3 = p_2(D)->bit;
(void) 0;
D.1199_8 = D.1176_3 != 0;
D.1177_9 = (unsigned int) D.1199_8;
return D.1177_9;
}
which the next forwprop pass optimizes to
foo (struct s * p)
{
unsigned int D.1177;
<unnamed-unsigned:1> D.1176;
<bb 2>:
D.1176_3 = p_2(D)->bit;
D.1177_9 = D.1176_3 != 0;
return D.1177_9;
}
andrew (struct s * p)
{
unsigned int D.1183;
<unnamed-unsigned:1> D.1182;
<bb 2>:
D.1182_3 = p_2(D)->bit;
D.1183_6 = D.1182_3 != 0;
return D.1183_6;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] New: don't use "if" to extract a single bit bit-field.
@ 2004-06-04 18:55 kazu at cs dot umass dot edu
2004-06-04 19:07 ` [Bug tree-optimization/15826] " pinskia at gcc dot gnu dot org
` (5 more replies)
0 siblings, 6 replies; 13+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-06-04 18:55 UTC (permalink / raw)
To: gcc-bugs
Transform foo() into bar().
struct s {
unsigned int bit : 1;
};
unsigned int
foo (struct s *p)
{
if (p->bit)
return 1;
else
return 0;
}
unsigned int
bar (struct s *p)
{
return (unsigned int) (p->bit);
}
Currently, the last tree-ssa form I get looks like so:
;; Function foo (foo)
foo (p)
{
int T.1;
unsigned int T.0;
<bb 0>:
T.0_2 = p_1->bit;
if (T.0_2 != 0) goto <L0>; else goto <L1>;
<L0>:;
return 1;
<L1>:;
return 0;
}
;; Function bar (bar)
bar (p)
{
<bb 0>:
return p_1->bit;
}
The assembly code:
.p2align 2,,3
.globl foo
.type foo, @function
foo:
testb $1, (%eax) # 43 *testqi_1/3 [length = 3]
setne %al # 40 *setcc_1 [length = 3]
movzbl %al, %eax # 45 *zero_extendqisi2_movzbw [length
= 3]
ret # 48 return_internal [length = 1]
.size foo, .-foo
.p2align 2,,3
.globl bar
.type bar, @function
bar:
movzbl (%eax), %eax # 28 *zero_extendqisi2_movzbw [length
= 3]
andl $1, %eax # 12 *andsi_1/1 [length = 3]
ret # 31 return_internal [length = 1]
.size bar, .-bar
Note that alias.i.t50.tailc contains:
<L22>:;
T.1776_58 = x_2->unchanging;
if (T.1776_58 != 0) goto <L25>; else goto <L26>;
<L25>:;
return 0;
<L26>:;
return 1;
--
Summary: don't use "if" to extract a single bit bit-field.
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at cs dot umass dot edu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
@ 2004-06-04 19:07 ` pinskia at gcc dot gnu dot org
2004-06-04 19:26 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 19:07 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-04 19:07 -------
Confirmed, this is related to bug 15618 which is for bools.
--
What |Removed |Added
----------------------------------------------------------------------------
BugsThisDependsOn| |15618
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2004-06-04 19:07:43
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
2004-06-04 19:07 ` [Bug tree-optimization/15826] " pinskia at gcc dot gnu dot org
@ 2004-06-04 19:26 ` pinskia at gcc dot gnu dot org
2004-06-07 17:59 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 19:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-04 19:26 -------
Here is another example:
struct s {
unsigned int bit : 1;
};
unsigned int
foo (struct s *p)
{
int i;
if (p->bit)
i = 1;
else
i = 0;
return i;
}
I will note that the example in comment #1 needs to have the return values merged together before the
real optimization happens (see PR 15268 and a patch which I posted but have not gotten around to
answering/tying RTH's question/seguestion yet).
But basically it can be optimization by putting a cast to bool first so a != 0 becomes (bool)a and PHI-
opt already optimizated out the branches.
--
What |Removed |Added
----------------------------------------------------------------------------
BugsThisDependsOn| |15268
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
2004-06-04 19:07 ` [Bug tree-optimization/15826] " pinskia at gcc dot gnu dot org
2004-06-04 19:26 ` pinskia at gcc dot gnu dot org
@ 2004-06-07 17:59 ` pinskia at gcc dot gnu dot org
2004-06-07 18:05 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-07 17:59 UTC (permalink / raw)
To: gcc-bugs
--
Bug 15826 depends on bug 15268, which changed state.
Bug 15268 Summary: [tree-ssa] return statements are not combined on the tree level
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15268
What |Old Value |New Value
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
` (2 preceding siblings ...)
2004-06-07 17:59 ` pinskia at gcc dot gnu dot org
@ 2004-06-07 18:05 ` pinskia at gcc dot gnu dot org
2004-06-16 6:21 ` kazu at cs dot umass dot edu
2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-07 18:05 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-07 18:05 -------
I should note now that PR 15268 is fixed, the only thing that is needed is for one-wide-bitfield != 0
needs to be converted to (_Bool)one-wide-bitfield.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
` (3 preceding siblings ...)
2004-06-07 18:05 ` pinskia at gcc dot gnu dot org
@ 2004-06-16 6:21 ` kazu at cs dot umass dot edu
2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 13+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-06-16 6:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2004-06-16 06:20 -------
Now that we have a single return statement, let me regenerate t50.tailc.
struct s {
unsigned int bit : 1;
};
unsigned int
foo (struct s *p)
{
if (p->bit)
return 1;
else
return 0;
}
unsigned int
bar (struct s *p)
{
return (unsigned int) (p->bit);
}
unsigned int
andrew (struct s *p)
{
int i;
if (p->bit)
i = 1;
else
i = 0;
return i;
}
I get:
;; Function foo (foo)
foo (p)
{
_Bool T.7;
unsigned int T.2;
int T.1;
unsigned int T.0;
<bb 0>:
T.0_3 = p_2->bit;
T.7_8 = T.0_3 != 0;
T.2_1 = (unsigned int)T.7_8;
return T.2_1;
}
;; Function bar (bar)
bar (p)
{
unsigned int T.3;
<bb 0>:
T.3_2 = p_1->bit;
return T.3_2;
}
;; Function andrew (andrew)
andrew (p)
{
_Bool T.16;
int i;
unsigned int T.6;
int T.5;
unsigned int T.4;
<bb 0>:
T.4_3 = p_2->bit;
T.16_9 = T.4_3 != 0;
i_1 = (int)T.16_9;
T.6_5 = (unsigned int)i_1;
return T.6_5;
}
So basically, the problems boils down to the tree combiner.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field.
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
` (4 preceding siblings ...)
2004-06-16 6:21 ` kazu at cs dot umass dot edu
@ 2005-05-04 1:52 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-04 1:52 UTC (permalink / raw)
To: gcc-bugs
--
Bug 15826 depends on bug 15618, which changed state.
Bug 15618 Summary: Missed bool optimization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15618
What |Old Value |New Value
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15826
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2020-04-19 18:28 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-15826-4@http.gcc.gnu.org/bugzilla/>
2012-01-24 0:55 ` [Bug tree-optimization/15826] don't use "if" to extract a single bit bit-field pinskia at gcc dot gnu.org
2014-10-31 4:01 ` pinskia at gcc dot gnu.org
2014-12-01 14:07 ` rguenth at gcc dot gnu.org
2020-04-19 18:28 ` law at redhat dot com
[not found] <bug-15826-5009@http.gcc.gnu.org/bugzilla/>
2006-03-02 14:24 ` pinskia at gcc dot gnu dot org
2007-04-05 21:01 ` steven at gcc dot gnu dot org
2008-04-30 19:22 ` rguenth at gcc dot gnu dot org
2004-06-04 18:55 [Bug tree-optimization/15826] New: " kazu at cs dot umass dot edu
2004-06-04 19:07 ` [Bug tree-optimization/15826] " pinskia at gcc dot gnu dot org
2004-06-04 19:26 ` pinskia at gcc dot gnu dot org
2004-06-07 17:59 ` pinskia at gcc dot gnu dot org
2004-06-07 18:05 ` pinskia at gcc dot gnu dot org
2004-06-16 6:21 ` kazu at cs dot umass dot edu
2005-05-04 1:52 ` pinskia at gcc dot gnu dot 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).