This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Eliminated function return values in retarget
- From: Michael Matz <matz at suse dot de>
- To: Jamie Iles <jamie at jamieiles dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 14 Oct 2014 16:24:13 +0200 (CEST)
- Subject: Re: Eliminated function return values in retarget
- Authentication-results: sourceware.org; auth=none
- References: <20141014094642 dot GA2509 at page dot Home>
Hi,
On Tue, 14 Oct 2014, Jamie Iles wrote:
> int foo(void)
> {
> if (getreturn() != 0)
> return -1;
>
> return 0;
> }
So if getreturn() returns zero it can simply reuse that return value ...
> but at -O1 I get
>
> 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
... and if I'm interpreting the mnemonics correctly that is what seems to
happen here. If $r0 is zero, then:
mov $r1, 0x0 $r1 = 0
sub $r1, $r1, $r0 $r1 = 0 - 0 = 0
or $r0, $r1, $r0 $r0 = 0 | 0 = 0
asr $r0, $r0, 0x1f $r0 = 0 >> 31 = 0
Voila, zero is correctly returned. Any non-zero value will be transformed
into -1 (if positive the high bit will be set due to subtraction, if
negative the high bit will be set due to the 'or', and the shift
replicates the high bit into the lower ones, yielding -1).
Ciao,
Michael.