This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ARM spurious load


The following code snippet produces code that loads a register, r5,
from memory, but never uses the value. The code is correct though, so
not a major issue. In addition, it never uses r3 or r12, which are
"free" registers, in that they don't have to be saved by the callee.
For a one line function that essentially returns a constant, the
generated code spills a lot of registers that it needn't. The
generated code ought to resemble "ldr r0, =constant0; ldr r1,
=constant1; b lr". This code was generated using arm-elf-gcc -mthumb
-O2.

Please cc me in your reply. Cheers,
Shaun

arm-elf-gcc (GCC) 4.0.2

#define USER_STACK 0x2100000

static long long rdp_getenv(void)
{
	// Return the command line in r0 and the stack in r1.
	return ((long long unsigned)USER_STACK << 32) | (int)"";
}

02001644 <rdp_getenv>:
  2001644:	b570      	push	{r4, r5, r6, lr}
  2001646:	4a04      	ldr	r2, [pc, #16]	(2001658 <.text+0x1658>)
  2001648:	4d04      	ldr	r5, [pc, #16]	(200165c <.text+0x165c>)
  200164a:	4e05      	ldr	r6, [pc, #20]	(2001660 <.text+0x1660>)
  200164c:	17d4      	asrs	r4, r2, #31
 200164e:	1c21      	adds	r1, r4, #0
  2001650:	4331      	orrs	r1, r6
 2001652:	1c10      	adds	r0, r2, #0
  2001654:	bd70      	pop	{r4, r5, r6, pc}
[the literal pool follows here]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]