This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Optimization Problem
- From: hideto-o at mwb dot biglobe dot ne dot jp
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 4 Apr 2002 15:08:32 +0900 (JST)
- Subject: Optimization Problem
I'm using gcc 2.9 cross compiler for MIPS3 (4650).
but I have a problem now. Please help me.
When I compile a C source below [LIST A] with optimization,
I got codes like [LIST B]. But LIST B is not right codes.
I guess gcc thinks that "if(f & 0x80000000)" means "if the leftmost bit of f is 1"
and gcc generates a code "bgez $a2,10".
Now, variable f (unsigned long) is 32 bits width and general registers of MIPS is 64 bits width,
so "if(f & 0x80000000)" and "bgez $a2,10" are not equal.
The former means to evaluate whether 32nd bit (from right) is 1, and the later means to evaluate
whethe 64th bit is 1. Because of wrong bit evaluation, my program doen't work well.
Is this a known problem of gcc and already fixed at currnent version?
Or did I make some mistakes, for example, I forgot using some useful options?
gcc -mips3 -mgp64 -O1 -c if.c
[LIST A]if.c
unsigned int
test (unsigned long x, unsigned long y, unsigned long f){
unsigned long r;
if (f & 0x80000000){
r=x * y;
}else{
r=x + y;
}
return r;
}
[LIST B]objdump -d if.o
if.o: file format elf32-bigmips
Disassembly of section .text:
0000000000000000 <test>:
0: 04c10003 bgez $a2,10 <test+0x10>
4: 00851021 addu $v0,$a0,$a1
8: 00850018 mult $a0,$a1
c: 00001012 mflo $v0
10: 03e00008 jr $ra
14: 00000000 nop
Thanks
--
OGAWA Hideto, Japan.
hideto-o@mwb.biglobe.ne.jp