* [arm] Fix thumb -fPIC
@ 2004-10-01 16:25 Paul Brook
2004-10-12 11:59 ` Richard Earnshaw
0 siblings, 1 reply; 4+ messages in thread
From: Paul Brook @ 2004-10-01 16:25 UTC (permalink / raw)
To: gcc-patches; +Cc: Richard Earnshaw
Patch below fixes a couple of bugswhen generating thumb PIC code.
One we are ORing with a register number rather than a bitmask. the other we
weren't searching all low regs when looking for a work register.
Tested with cross to arm-none-elf.
Applied as obvious to csl-arm-branch and mainline as this has been discussed
before.
Paul
2004-01-01 Paul Brook <paul@codesourcery.com>
* config/arm/arm.c (thumb_compute_saved_rag_mask): Or with bitmask,
not register number.
(thumb_find_work_register): Search full register range.
Index: gcc/config/arm/arm.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.303.2.58
diff -u -p -r1.303.2.58 arm.c
--- gcc/config/arm/arm.c 30 Sep 2004 21:45:04 -0000 1.303.2.58
+++ gcc/config/arm/arm.c 1 Oct 2004 15:22:59 -0000
@@ -3040,7 +3040,7 @@ thumb_find_work_register (int live_regs_
return LAST_ARG_REGNUM;
/* Look for a pushed register. */
- for (reg = 0; reg < LAST_LO_REGNUM; reg++)
+ for (reg = LAST_LO_REGNUM; reg >=0; reg--)
if (live_regs_mask & (1 << reg))
return reg;
@@ -9178,7 +9178,7 @@ thumb_compute_save_reg_mask (void)
}
if (flag_pic && !TARGET_SINGLE_PIC_BASE)
- mask |= PIC_OFFSET_TABLE_REGNUM;
+ mask |= (1 << PIC_OFFSET_TABLE_REGNUM);
if (TARGET_SINGLE_PIC_BASE)
mask &= ~(1 << arm_pic_register);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [arm] Fix thumb -fPIC
2004-10-01 16:25 [arm] Fix thumb -fPIC Paul Brook
@ 2004-10-12 11:59 ` Richard Earnshaw
2004-10-12 19:14 ` Paul Brook
0 siblings, 1 reply; 4+ messages in thread
From: Richard Earnshaw @ 2004-10-12 11:59 UTC (permalink / raw)
To: Paul Brook; +Cc: gcc-patches
On Fri, 2004-10-01 at 16:45, Paul Brook wrote:
> Patch below fixes a couple of bugswhen generating thumb PIC code.
> One we are ORing with a register number rather than a bitmask. the other we
> weren't searching all low regs when looking for a work register.
>
> Tested with cross to arm-none-elf.
> Applied as obvious to csl-arm-branch and mainline as this has been discussed
> before.
>
> Paul
>
> 2004-01-01 Paul Brook <paul@codesourcery.com>
>
> * config/arm/arm.c (thumb_compute_saved_rag_mask): Or with bitmask,
> not register number.
> (thumb_find_work_register): Search full register range.
I'm not 100% sure about the second issue. LAST_LO_REGNUM is sometimes
used as a frame pointer register when we can't manage without one, have
you checked that it's safe to use it as a scratch in these conditions
(it may be, but I'm not sure).
Other part is OK.
R.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [arm] Fix thumb -fPIC
2004-10-12 11:59 ` Richard Earnshaw
@ 2004-10-12 19:14 ` Paul Brook
2004-10-13 9:08 ` Richard Earnshaw
0 siblings, 1 reply; 4+ messages in thread
From: Paul Brook @ 2004-10-12 19:14 UTC (permalink / raw)
To: gcc-patches; +Cc: Richard Earnshaw
> > (thumb_find_work_register): Search full register range.
>
> I'm not 100% sure about the second issue. LAST_LO_REGNUM is sometimes
> used as a frame pointer register when we can't manage without one, have
> you checked that it's safe to use it as a scratch in these conditions
> (it may be, but I'm not sure).
I checked the function prologue usage, but missed the the use from
builtin_setjmp_reciever. Patch below fixes this case, which seemed to be
working by chance.
Tested with cross to arm-none-elf.
Ok?
Paul
2004-10-12 Paul Brook <paul@codesourcery.com>
* config/arm/arm-protos.h (arm_load_pic_register): Update prototype.
* config/arm/arm.c (thumb_find_work_register): Update comments.
(arm_load_pic_register): Add argument for scratch register.
(arm_expand_prologue, thumb_expand_prologue): Pass extra argument.
* config/arm/arm.md (builtin_setjmp_receiver): Ditto.
Index: config/arm/arm-protos.h
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/arm/arm-protos.h,v
retrieving revision 1.77
diff -u -p -r1.77 arm-protos.h
--- config/arm/arm-protos.h 24 Aug 2004 20:16:40 -0000 1.77
+++ config/arm/arm-protos.h 12 Oct 2004 18:05:54 -0000
@@ -27,7 +27,7 @@
extern void arm_override_options (void);
extern int use_return_insn (int, rtx);
extern int arm_regno_class (int);
-extern void arm_load_pic_register (void);
+extern void arm_load_pic_register (unsigned int);
extern int arm_volatile_func (void);
extern const char *arm_output_epilogue (rtx);
extern void arm_expand_prologue (void);
Index: config/arm/arm.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.411
diff -u -p -r1.411 arm.c
--- config/arm/arm.c 12 Oct 2004 16:43:56 -0000 1.411
+++ config/arm/arm.c 12 Oct 2004 18:07:12 -0000
@@ -3023,7 +3023,8 @@ thumb_find_work_register (int live_regs_
if (!regs_ever_live[LAST_ARG_REGNUM])
return LAST_ARG_REGNUM;
- /* Look for a pushed register. */
+ /* Look for a pushed register. This is used before the frame pointer is
+ setup, so r7 is a candidate. */
for (reg = LAST_LO_REGNUM; reg >=0; reg--)
if (live_regs_mask & (1 << reg))
return reg;
@@ -3033,10 +3034,11 @@ thumb_find_work_register (int live_regs_
}
-/* Generate code to load the PIC register. */
+/* Generate code to load the PIC register. In thumb mode SCRATCH is a
+ low register. */
void
-arm_load_pic_register (void)
+arm_load_pic_register (unsigned int scratch)
{
#ifndef AOF_ASSEMBLER
rtx l1, pic_tmp, pic_tmp2, pic_rtx;
@@ -3071,12 +3073,9 @@ arm_load_pic_register (void)
{
if (REGNO (pic_offset_table_rtx) > LAST_LO_REGNUM)
{
- int reg;
-
/* We will have pushed the pic register, so should always be
able to find a work register. */
- reg = thumb_find_work_register (thumb_compute_save_reg_mask ());
- pic_tmp = gen_rtx_REG (SImode, reg);
+ pic_tmp = gen_rtx_REG (SImode, scratch);
emit_insn (gen_pic_load_addr_thumb (pic_tmp, pic_rtx));
emit_insn (gen_movsi (pic_offset_table_rtx, pic_tmp));
}
@@ -10237,7 +10236,7 @@ arm_expand_prologue (void)
if (flag_pic)
- arm_load_pic_register ();
+ arm_load_pic_register (INVALID_REGNUM);
/* If we are profiling, make sure no instructions are scheduled before
the call to mcount. Similarly if the user has requested no
@@ -12964,10 +12963,11 @@ thumb_expand_prologue (void)
return;
}
+ live_regs_mask = thumb_compute_save_reg_mask ();
/* Load the pic register before setting the frame pointer, so we can use r7
as a temporary work register. */
if (flag_pic)
- arm_load_pic_register ();
+ arm_load_pic_register (thumb_find_work_register (live_regs_mask));
offsets = arm_get_frame_offsets ();
@@ -12978,7 +12978,6 @@ thumb_expand_prologue (void)
RTX_FRAME_RELATED_P (insn) = 1;
}
- live_regs_mask = thumb_compute_save_reg_mask ();
amount = offsets->outgoing_args - offsets->saved_regs;
if (amount)
{
Index: config/arm/arm.md
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/arm/arm.md,v
retrieving revision 1.183
diff -u -p -r1.183 arm.md
--- config/arm/arm.md 12 Oct 2004 13:56:03 -0000 1.183
+++ config/arm/arm.md 12 Oct 2004 18:05:54 -0000
@@ -4459,7 +4459,9 @@
"flag_pic"
"
{
- arm_load_pic_register ();
+ /* r3 is clobbered by set/longjmp, so we can use it as a scratch
+ register. */
+ arm_load_pic_register (3);
DONE;
}")
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [arm] Fix thumb -fPIC
2004-10-12 19:14 ` Paul Brook
@ 2004-10-13 9:08 ` Richard Earnshaw
0 siblings, 0 replies; 4+ messages in thread
From: Richard Earnshaw @ 2004-10-13 9:08 UTC (permalink / raw)
To: Paul Brook; +Cc: gcc-patches
On Tue, 2004-10-12 at 19:51, Paul Brook wrote:
> > > (thumb_find_work_register): Search full register range.
> >
> > I'm not 100% sure about the second issue. LAST_LO_REGNUM is sometimes
> > used as a frame pointer register when we can't manage without one, have
> > you checked that it's safe to use it as a scratch in these conditions
> > (it may be, but I'm not sure).
>
> I checked the function prologue usage, but missed the the use from
> builtin_setjmp_reciever. Patch below fixes this case, which seemed to be
> working by chance.
>
> Tested with cross to arm-none-elf.
> Ok?
>
> Paul
>
> 2004-10-12 Paul Brook <paul@codesourcery.com>
>
> * config/arm/arm-protos.h (arm_load_pic_register): Update prototype.
> * config/arm/arm.c (thumb_find_work_register): Update comments.
> (arm_load_pic_register): Add argument for scratch register.
> (arm_expand_prologue, thumb_expand_prologue): Pass extra argument.
> * config/arm/arm.md (builtin_setjmp_receiver): Ditto.
OK.
R.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-10-13 8:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-01 16:25 [arm] Fix thumb -fPIC Paul Brook
2004-10-12 11:59 ` Richard Earnshaw
2004-10-12 19:14 ` Paul Brook
2004-10-13 9:08 ` Richard Earnshaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).