Article View: gnu.gcc.bug
Article #6310silly branching on sparc
From: Mark Bromley
Date: Thu, 14 Dec 1995 00:00
Date: Thu, 14 Dec 1995 00:00
73 lines
1757 bytes
1757 bytes
This gcc 2.7 on a supersparc, sunos4.1.3_U1. The code produced for
the following function has somewhat silly branching:
int foo (long w, long x, long y, long z)
{
if ((w & x) | (y & z))
return 3;
else if ((x ^ y) | (w ^ z))
return 4;
else
return 5;
}
The output of gcc -S -O2 -msupersparc is:
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 4
.global _foo
.proc 04
_foo:
!#PROLOGUE# 0
!#PROLOGUE# 1
and %o0,%o1,%g3
and %o2,%o3,%g2
orcc %g3,%g2,%g0
be L2
xor %o1,%o2,%g3
b L6
mov 3,%o0
L2:
xor %o0,%o3,%g2
orcc %g3,%g2,%g0
bne L6
mov 4,%o0
mov 5,%o0
L6:
retl
nop
The "right" code would be:
_foo:
!#PROLOGUE# 0
!#PROLOGUE# 1
and %o0,%o1,%g3
and %o2,%o3,%g2
orcc %g3,%g2,%g0
bne L6
mov 3,%o0
L2:
xor %o1,%o2,%g3
xor %o0,%o3,%g2
orcc %g3,%g2,%g0
bne L6
mov 4,%o0
mov 5,%o0
L6:
retl
nop
In my version when %g2 | %g3 is 0, there is one wasted instruction and
none when %g2 | %g3 is non zero. In the original code there are no
wasted instructions for the zero case, but there are two wasted
instructions for the non zero case. These are actually wasted cycles
since there is an instruction grouping break between each of
instructions following the first be when it is not taken.
xor %o1,%o2,%g3
b L6
mov 3,%o0
Technical Details
Message-ID:
<199512142313.SAA18658@gate3.fmr.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,4c51abca834685d5,start X-Google-Attributes: gid113d02,public From: a200739@vantage.fmr.COM (Mark Bromley) Subject: silly branching on sparc Date: 1995/12/14 Message-ID: <199512142313.SAA18658@gate3.fmr.com> X-Deja-AN: 121854794 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug