Bug 49207 - Instruction scheduling error in GCC mips cross-compiler
Summary: Instruction scheduling error in GCC mips cross-compiler
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-28 06:18 UTC by hanib
Modified: 2013-11-10 05:33 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
preprocessed file (43.58 KB, application/octet-stream)
2011-05-28 06:19 UTC, hanib
Details
assembly language file (4.67 KB, text/x-asm)
2011-05-28 06:20 UTC, hanib
Details

Note You need to log in before you can comment on or make changes to this bug.
Description hanib 2011-05-28 06:18:10 UTC
When compiling a testbench program using -O2 optimization, the GCC MIPS cross-compiler generates an incorrect instruction sequence (a store before a load to the same memory location) which leads to a memory corruption problem and crashes the program. If the -O1 or -O0 switches are used, this problem does not occur.

The output of the gcc -v -save-temps command is included below and the test.i file is attached. I am also including, below, the portion of assembly code that contains the erroneous instruction sequence (see arrows).

/mnt/disk/home/tools/mipsel/bin/mipsel-linux-gcc   -v -save-temps -O2 -static   -DSPEC_CPU_LINUX_IA32       test.o             -lm        -o perlbench
Using built-in specs.
Target: mipsel-linux
Configured with: ../../src/gcc-4.4.3/configure --target=mipsel-linux --prefix=/mnt/disk/home/tools/mipsel --with-sysroot=/mnt/disk/home/tools/mipsel --disable-libssp --disable-libgomp --disable-libmudflap --disable-nls --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.4.3 (GCC) 
COMPILER_PATH=/mnt/disk/home/tools/mipsel/libexec/gcc/mipsel-linux/4.4.3/:/mnt/disk/home/tools/mipsel/libexec/gcc/mipsel-linux/4.4.3/:/mnt/disk/home/tools/mipsel/libexec/gcc/mipsel-linux/:/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/:/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/:/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/../../../../mipsel-linux/bin/
LIBRARY_PATH=/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/:/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/../../../../mipsel-linux/lib/:/mnt/disk/home/tools/mipsel/lib/:/mnt/disk/home/tools/mipsel/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-static' '-DSPEC_CPU_LINUX_IA32' '-o' 'perlbench' '-mllsc' '-mno-shared'
 /mnt/disk/home/tools/mipsel/libexec/gcc/mipsel-linux/4.4.3/collect2 --sysroot=/mnt/disk/home/tools/mipsel -EL -static -o perlbench /mnt/disk/home/tools/mipsel/usr/lib/crt1.o /mnt/disk/home/tools/mipsel/usr/lib/crti.o /mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/crtbeginT.o -L/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3 -L/mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/../../../../mipsel-linux/lib -L/mnt/disk/home/tools/mipsel/lib -L/mnt/disk/home/tools/mipsel/usr/lib test.o -lm --start-group -lgcc -lgcc_eh -lc --end-group /mnt/disk/home/tools/mipsel/lib/gcc/mipsel-linux/4.4.3/crtend.o /mnt/disk/home/tools/mipsel/usr/lib/crtn.o
/mnt/disk/home/tools/mipsel/usr/lib/crt1.o: In function `__start':

>>>>>>>>>>>>>>>>>>>>>>> assembly code >>>>>>>>>>>>>>>>>>>>

$L100:
	lw	$3,%got(PL_xiv_root)($28)
	lw	$2,0($16)
	lw	$5,0($3)
	addiu	$4,$2,12
>>>>	sw	$5,12($2)
>>>>	lw	$19,12($2)
	li	$2,2			# 0x2
	beq	$17,$2,$L184
	sw	$4,0($3)

	beq	$18,$0,$L111
	nop

	move	$20,$0
	move	$21,$0
	move	$18,$0
Comment 1 hanib 2011-05-28 06:19:34 UTC
Created attachment 24384 [details]
preprocessed file
Comment 2 hanib 2011-05-28 06:20:36 UTC
Created attachment 24385 [details]
assembly language file
Comment 3 Andrew Pinski 2011-05-28 09:32:38 UTC
I think you have an aliasing problem in your code.
Comment 4 hanib 2011-05-28 21:21:40 UTC
(In reply to comment #3)
> I think you have an aliasing problem in your code.

The code I am compiling is the Perlbench benchmark from SPEC-CPU2006. If I compile the code for an Intel machine using -O2 there is no problem. This problem only appears when I use the GCC MIPS cross-compiler with the -O2 switch. I also traced through the code and the sequence of these two instructions should be reversed.
Comment 5 Andrew Pinski 2013-11-10 05:33:56 UTC
(In reply to hanib from comment #4)
> (In reply to comment #3)
> > I think you have an aliasing problem in your code.
> 
> The code I am compiling is the Perlbench benchmark from SPEC-CPU2006. If I
> compile the code for an Intel machine using -O2 there is no problem. This
> problem only appears when I use the GCC MIPS cross-compiler with the -O2
> switch. I also traced through the code and the sequence of these two
> instructions should be reversed.

Perl in SPEC CPU 2006 has known aliasing bugs in it; just use -fno-strict-aliasing.