Non-optimal access to constants

Nadezhda Ivanоvna Vyukova
Fri Jun 11 15:34:00 GMT 2010

I use gcc-4.1.2 for MIPS64 configured as

/tmp/gcc-4.1.2/configure --target=mips64-none-elf --enable-threads=no
--disable-shared --enable-long-long --enable-c99 --enable-languages=c
--enable-multilib --enable-symvers=gnu --disable-libmudflap
--disable-libssp --disable-libgcc_eh --with-newlib --with-dwarf2
--with-system-zlib --enable-checking=release
--enable-generated-files-in-srcdir --verbose --prefix=/home/niva/local
--srcdir=/tmp/gcc-4.1.2 --enable-cpp

I compile the file poly.c:

  double poly(double x)
    double y = 1.0 + x * (2.0 + x * (3.0 + x * (4.0 + x)));
    return y;

using the following command line:

mips64-none-elf-gcc-4.1.2 -O3 -fno-merge-constants -mips64 -Wall -W -S
-o ttt.s ttt.c -G0

(I cannot use -G8 because the operating environment does not allow use
of .sdata sections.)

The resulting assembler code looks like this:
	.align	3
	.word	1074790400
	.word	0
	.align	3
	.word	1074266112
	.word	0
	.align	3
	.word	1073741824
	.word	0
	.align	3
	.word	1072693248
	.word	0
	.align	2
	.align	3
	.globl	poly
	.ent	poly
	.frame	$sp,0,$31		# vars= 0, regs= 0/0, args= 0, gp= 0
	.mask	0x00000000,0
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro

	lui	$2,%hi($LC0)	
	ldc1	$f0,%lo($LC0)($2)
	lui	$2,%hi($LC1)	 
	ldc1	$f1,%lo($LC1)($2)
	add.d	$f0,$f12,$f0	 
	lui	$2,%hi($LC2)	 
	madd.d	$f0,$f1,$f12,$f0
	ldc1	$f1,%lo($LC2)($2)
	lui	$2,%hi($LC3)	 
	madd.d	$f0,$f1,$f12,$f0
	ldc1	$f1,%lo($LC3)($2)
	j	$31
	madd.d	$f0,$f1,$f12,$f0

Two commands are used to access each constant.

Q: Is it possible to make GCC use a common base register for
accessing all of the constants in a function?

More information about the Gcc-help mailing list