This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug web/43473] New: hword size destination variable induces suboptimal code generation compared to full word size var
- From: "mirq-gccboogs at rere dot qmqm dot pl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 Mar 2010 20:30:44 -0000
- Subject: [Bug web/43473] New: hword size destination variable induces suboptimal code generation compared to full word size var
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
unsigned short a;
unsigned b;
#define d 0xC000
void ma()
{
unsigned short u = (d >> 1) & 0x55555555;
a = (a & ~u) | d;
}
void mb()
{
unsigned short u = (d >> 1) & 0x55555555;
b = (b & ~u) | d;
}
generates:
ma:
ldr r3, .L2
ldrh r2, [r3, #0]
mvn r2, r2, asl #18
mvn r2, r2, lsr #18
strh r2, [r3, #0] @ movhi
bx lr
.L2:
.word a
mb:
ldr r3, .L5
ldr r2, [r3, #0]
orr r2, r2, #49152
str r2, [r3, #0]
bx lr
.L5:
.word b
This is with -O. Without optimization it looks even worse:
(gcc 4.5 svn 157582)
Code without -O looks even worse:
mov r3, #16384
strh r3, [fp, #-6] @ movhi
ldrh r3, [fp, #-6]
mvn r3, r3
mov r3, r3, asl #16
mov r2, r3, lsr #16
ldr r3, .L2
ldrh r3, [r3, #0]
mov r3, r3, asl #16
mov r3, r3, lsr #16
and r3, r2, r3
mov r3, r3, asl #16
mov r3, r3, lsr #16
mvn r3, r3, asl #18
mvn r3, r3, lsr #18
mov r3, r3, asl #16
mov r3, r3, lsr #16
mov r3, r3, asl #16
mov r2, r3, lsr #16
ldr r3, .L2
strh r2, [r3, #0] @ movhi
compared to:
mov r3, #16384
strh r3, [fp, #-6] @ movhi
ldrh r3, [fp, #-6]
mvn r3, r3
mov r2, r3
ldr r3, .L5
ldr r3, [r3, #0]
and r3, r2, r3
orr r2, r3, #49152
ldr r3, .L5
str r2, [r3, #0]
--
Summary: hword size destination variable induces suboptimal code
generation compared to full word size var
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: web
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mirq-gccboogs at rere dot qmqm dot pl
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-none-eabi
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43473