Hi folks, I'm retargetting GCC to a custom architecture (https://github.com/jamieiles/gcc-oldland is the retarget) and have an odd problem with function return values near the end of a function being eliminated. For example:
extern int getreturn(void); int foo(void) { if (getreturn() != 0) return -1; return 0; } I see that with optimization (-O1 or greater) that this gets compiled into a call to getreturn() and then unconditionally sets the return value to -1 (with a one_cmpl + eor + ior). Inserting a call to another function inbetween the 'return -1' and 'return 0' is enough to cause working code to be generated. works fine at -O0 generating 00000000 <foo>: 0: f0 ce ff 93 str32 $lr, [$sp, 0x1ffc] 4: d0 8e ff 93 str32 $fp, [$sp, 0x1ff8] 8: 0d 8e 00 08 sub $fp, $sp, 0x8 c: 0e 8e 00 08 sub $sp, $sp, 0x8 10: fb ff ff 40 call 0 <foo> 10: R_OLDLAND_PC24 getreturn-0x4 14: 01 00 00 3e mov $r1, $r0 18: 00 00 00 3c mov $r0, 0x0 1c: 00 01 00 32 cmp $r1, $r0 20: 03 00 00 58 beq 30 <foo+0x30> 24: 00 fc ff ef movhi $r0, 0xffff 28: 00 fc ff f7 orlo $r0, $r0, 0xffff 2c: 01 00 00 50 b 34 <foo+0x34> 30: 00 00 00 3c mov $r0, 0x0 34: 0e 8e 00 00 add $sp, $sp, 0x8 38: 0d 8e 00 00 add $fp, $sp, 0x8 3c: 0d 8e ff 83 ldr32 $fp, [$sp, 0x1ff8] 40: 0f ce ff 83 ldr32 $lr, [$sp, 0x1ffc] 44: f0 00 00 46 ret but at -O1 I get 00000000 <foo>: 0: f0 ce ff 93 str32 $lr, [$sp, 0x1ffc] 4: d0 8e ff 93 str32 $fp, [$sp, 0x1ff8] 8: 0d 8e 00 08 sub $fp, $sp, 0x8 c: 0e 8e 00 08 sub $sp, $sp, 0x8 10: fb ff ff 40 call 0 <foo> 10: R_OLDLAND_PC24 getreturn-0x4 14: 01 00 00 3c mov $r1, 0x0 18: 01 01 00 0a sub $r1, $r1, $r0 1c: 00 01 00 2a or $r0, $r1, $r0 20: 00 f0 01 38 asr $r0, $r0, 0x1f 24: 0e 8e 00 00 add $sp, $sp, 0x8 28: 0d 8e 00 00 add $fp, $sp, 0x8 2c: 0d 8e ff 83 ldr32 $fp, [$sp, 0x1ff8] 30: 0f ce ff 83 ldr32 $lr, [$sp, 0x1ffc] 34: f0 00 00 46 ret I have $r0-$r5 as call used registers and my TARGET_FUNCTION_VALUE and TARGET_FUNCTION_VALUE_REGNO_P using $r0. Any pointers would be greatfully received. Regards, Jamie