This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/15826] New: don't use "if" to extract a single bit bit-field.
- From: "kazu at cs dot umass dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Jun 2004 18:55:55 -0000
- Subject: [Bug tree-optimization/15826] New: don't use "if" to extract a single bit bit-field.
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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