This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
minor optimization missed on SH
- To: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Subject: minor optimization missed on SH
- From: "Schirmer, Hartmut" <SchirmerH at Innovative-Systems dot de>
- Date: Wed, 15 Aug 2001 10:24:14 +0200
Hi,
the following code
-------------------
struct
{
long x;
short y;
struct
{
unsigned a : 12;
unsigned b : 4;
} s;
} u;
unsigned test(void)
{
return u.s.a;
}
-------------------
compiles to
-------------------
.file "bitf.i"
.data
! GNU C version 3.0 20010611 (prerelease) (sh-hitachi-coff)
! compiled by GNU C version 2.95.3-4 (cygwin special).
! options passed: -fpreprocessed -mrelax -m1 -ansi -O -Wall
! -Wwrite-strings -Wno-trigraphs -Wunused -Wno-main -Wundef
! -Wmissing-declarations -Wpointer-arith -ansi -fverbose-asm
! -fno-keep-static-consts -fno-strict-aliasing -fomit-frame-pointer
! options enabled: -fdefer-pop -fomit-frame-pointer -fthread-jumps
! -fpeephole -ffunction-cse -finline -freg-struct-return -fdelayed-branch
! -fsched-interblock -fsched-spec -fbranch-count-reg -fcommon -fverbose-asm
! -fgnu-linker -fargument-alias -fident -fguess-branch-probability
! -fmath-errno -m1 -mrelax
.text
.align 2
.global _test
_test:
mov.l L2,r1
mov.l @(4,r1),r0
shll16 r0
shlr16 r0
shlr2 r0
rts
shlr2 r0
L3:
.align 2
L2:
.long _u
.comm _u,8
.ident "GCC: (GNU) 3.0 20010611 (prerelease)"
-------------------
the sequence
shll16 r0
shlr16 r0
clears the upper 16bit of r0. Using
extu.w r0
would be faster and shorter.
GCC 2.95.2 produces the same code. Code is identical on
ever optimisation level > 0
Hartmut