target/1947: gcc for target xscale generates incorrect code when optimization is turned on
vmoorthy@giganet.com
vmoorthy@giganet.com
Mon Feb 12 07:56:00 GMT 2001
>Number: 1947
>Category: target
>Synopsis: gcc for target xscale generates incorrect code when optimization is turned on
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Feb 12 07:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Vijay Moorthy
>Release: 2.9-xscale-001130
>Organization:
>Environment:
gcc for target==xscale-elf build=sun-sparc-solaris2.8
>Description:
Here a test program. Note that testa and testb should behave differently.
In particular is x is big positive and y is big negative, the subtraction
will overflow resulting in a negative number, whereas the "<" should be
false. The compiler however generates the same code for each when optimizations
are turned on.
int testa(int x,int y) {
if ( x-y < 0 )
return 1;
else
return 0;
}
int testb(int x, int y) {
if ( x < y )
return 1;
else
return 2;
}
This problem seems to be specific to the xscale target, and
does not occur for the "strongarm" target.
>How-To-Repeat:
Here is complete C source :
-----------------------------
int testa(int x,int y) {
if ( x-y < 0 )
return 1;
else
return 0;
}
int testb(int x, int y) {
if ( x < y )
return 1;
else
return 2;
}
---------------------------------
Compile with the following command line:
xscale-elf-gcc -S -O2 test.c
The following is the (incorrect) assembly output:
-----------------------------------
@ Generated by gcc 2.9-xscale-001130 for ARM/elf
.file "test.c"
.gcc2_compiled.:
.text
.align 2
.global testa
.type testa,function
testa:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, current_function_anonymous_args = 0
cmp r0, r1
movge r0, #0
movlt r0, #1
mov pc, lr
.Lfe1:
.size testa,.Lfe1-testa
.align 2
.global testb
.type testb,function
testb:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, current_function_anonymous_args = 0
cmp r0, r1
movge r0, #2
movlt r0, #1
mov pc, lr
.Lfe2:
.size testb,.Lfe2-testb
--------------------------------------------
Without optimizations, the following (correct) code is genertated:
---------------------------------------------
@ Generated by gcc 2.9-xscale-001130 for ARM/elf
.file "test.c"
.gcc2_compiled.:
.text
.align 2
.global testa
.type testa,function
testa:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, current_function_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
sub sp, sp, #8
str r0, [fp, #-16]
str r1, [fp, #-20]
ldr r3, [fp, #-16]
ldr r2, [fp, #-20]
rsb r3, r2, r3
cmp r3, #0
bge .L3
mov r0, #1
b .L2
b .L4
.L3:
mov r0, #0
b .L2
.L4:
.L2:
ldmea fp, {fp, sp, pc}
.Lfe1:
.size testa,.Lfe1-testa
.align 2
.global testb
.type testb,function
testb:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, current_function_anonymous_args = 0
mov ip, sp
stmfd sp!, {fp, ip, lr, pc}
sub fp, ip, #4
sub sp, sp, #8
str r0, [fp, #-16]
str r1, [fp, #-20]
ldr r3, [fp, #-16]
ldr r2, [fp, #-20]
cmp r3, r2
bge .L6
mov r0, #1
b .L5
b .L7
.L6:
mov r0, #2
b .L5
.L7:
.L5:
ldmea fp, {fp, sp, pc}
.Lfe2:
.size testb,.Lfe2-testb
------------------------------------------------
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list