public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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; 7+ 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] 7+ 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: don't use "if" to extract a single bit bit-field 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; 7+ 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] 7+ 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: don't use "if" to extract a single bit bit-field 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; 7+ 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] 7+ 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: don't use "if" to extract a single bit bit-field 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; 7+ 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] 7+ 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: don't use "if" to extract a single bit bit-field 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; 7+ 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] 7+ 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: don't use "if" to extract a single bit bit-field 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; 7+ 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] 7+ 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: don't use "if" to extract a single bit bit-field 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; 7+ 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] 7+ messages in thread
end of thread, other threads:[~2005-05-04 1:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-04 18:55 [Bug tree-optimization/15826] New: don't use "if" to extract a single bit bit-field 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).