Article View: gnu.gcc.help
Article #53373constants
From: Serge Adda
Date: Tue, 07 Jan 1992 13:31
Date: Tue, 07 Jan 1992 13:31
105 lines
3180 bytes
3180 bytes
Hello,
Most of the RISC architectures have a limited number
bits in the field holding immediat operand. When the
constant is too wide, it is not possible to use this
field; so the compiler has to generate few instruc-
tions (2 on a 32-bit machine) to load the constant
into a register.
The problem with gcc is that transformation of an
immediat operand into a register load is performed
by the last pass (instruction selection). If this
transformation takes place inside a loop, the load
could be move outside of the loop, but because the
strength-reduction optimization has already been
done, it is too late for that.
----------------------------------------------------
foo(int a[], int b[], int n)
{
int i;
for (i = 0; i < n; i++)
{
a[i] = b[i] + 5000;
}
}
----------------------------------------------------
example 1
The code below has been generated by gcc-1.40 with
"-O -fstrength-reduce" on a Sparc station for the
example 1:
----------------------------------------------------
gcc_compiled.:
.text
.align 4
.global _foo
.proc 1
_foo:
!#PROLOGUE# 0
save %sp,-112,%sp
!#PROLOGUE# 1
mov %i0,%o0
mov %i1,%o2
mov %i2,%o4
mov 0,%o1
cmp %o1,%o4
bge L6
nop
mov %o0,%o3
L5:
ld [%o2],%o0
sethi %hi(5000),%g1
or %lo(5000),%g1,%g1
add %o0,%g1,%o0
st %o0,[%o3]
add %o3,4,%o3
add %o2,4,%o2
add %o1,1,%o1
cmp %o1,%o4
bl L5
nop
L6:
ret
restore
----------------------------------------------------
The code below has been generated by acc, (the Sun
ansi compiler) for the same example. You can notice
that, this time, the register load, is outside of the
loop.
----------------------------------------------------
.seg "text" ! [internal]
!.file "foo.c"
!ident "acomp: (CDS) SunOS5.0 IDR3.5 (H6.1) 11/01/90"
.proc 16
.align 4
.global _foo
_foo:
mov 0,%o5
cmp %o5,%o2
sethi %hi(0x1388),%o3
bge LE12
add %o3,%lo(0x1388),%o4
LY1: ! [internal]
ld [%o1],%o3
inc %o5
add %o3,%o4,%o3
cmp %o5,%o2
inc 4,%o1
st %o3,[%o0]
bl LY1
inc 4,%o0
LE12:
retl
nop ! [internal]
----------------------------------------------------
So, is anybody is able to suggest a way to do the
same with gcc, I will be pleased to know it. Thanx.
Bye.
Serge Adda
A.C.R.I. Compiler Team
Technical Details
Message-ID:
<9201071325.AA21597@mickey.acri.fr>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!cs.utexas.edu!qt.cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mickey.acri.FR!addaShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,9b9964644f064990,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1992-01-07 07:39:40 PST Newsgroups: gnu.gcc.help Path: arc1-ca.pugleaf.net!sparky!uunet!usc!cs.utexas.edu!qt.cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mickey.acri.FR!adda From: adda@mickey.acri.FR (Serge Adda) Subject: constants Message-ID: <9201071325.AA21597@mickey.acri.fr> Sender: daemon@cis.ohio-state.edu Organization: Advanced Computer Research Institute Distribution: gnu Date: Tue, 7 Jan 1992 13:31:36 GMT Lines: 105