This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix PR44169, load_toc_v4_PIC_1b
- From: Alan Modra <amodra at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Edelsohn <edelsohn at gnu dot org>
- Date: Mon, 31 May 2010 16:27:10 +0930
- Subject: Fix PR44169, load_toc_v4_PIC_1b
load_toc_v4_PIC_1b is an unspec that sets lr to the location of a word
containing a pc-relative _GLOBAL_OFFSET_TABLE_ address. Currently
the rtl doesn't contain anything that says the output depends on pc,
so gcc is free to combine two occurrences of this insn. At one stage
in gcc's history, the entire sequence of insns using this one to set
up the got pointer was marked with REG_LIBCALL/REG_RETVAL notes. When
optimizing, gcc used to combine the entire sequence with a previous
sequence, but at -O1 we now emit wrong code.
Fixed by adding a label to the rtl. Bootstrapped and regression
tested powerpc-linux. OK mainline and branches?
PR target/44169
* config/rs6000/rs6000.md (load_toc_v4_PIC_1b): Add label operand.
* config/rs6000/rs6000.c (rs6000_legitimize_tls_address): Pass label
rtx to gen_load_toc_v4_PIC_1b. Tidy.
(rs6000_emit_load_toc_table): Likewise.
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c (revision 160024)
+++ gcc/config/rs6000/rs6000.c (working copy)
@@ -5418,20 +5419,16 @@ rs6000_legitimize_tls_address (rtx addr,
rs6000_emit_move (got, gsym, Pmode);
else
{
- rtx tmp3, mem;
- rtx last;
+ rtx mem, lab, last;
tmp1 = gen_reg_rtx (Pmode);
tmp2 = gen_reg_rtx (Pmode);
- tmp3 = gen_reg_rtx (Pmode);
mem = gen_const_mem (Pmode, tmp1);
-
- emit_insn (gen_load_toc_v4_PIC_1b (gsym));
- emit_move_insn (tmp1,
- gen_rtx_REG (Pmode, LR_REGNO));
+ lab = gen_label_rtx ();
+ emit_insn (gen_load_toc_v4_PIC_1b (gsym, lab));
+ emit_move_insn (tmp1, gen_rtx_REG (Pmode, LR_REGNO));
emit_move_insn (tmp2, mem);
- emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
- last = emit_move_insn (got, tmp3);
+ last = emit_insn (gen_addsi3 (got, tmp1, tmp2));
set_unique_reg_note (last, REG_EQUAL, gsym);
}
}
@@ -17837,12 +17911,12 @@ rs6000_emit_load_toc_table (int fromprol
}
else
{
- rtx tocsym;
+ rtx tocsym, lab;
tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
- emit_insn (gen_load_toc_v4_PIC_1b (tocsym));
- emit_move_insn (dest,
- gen_rtx_REG (Pmode, LR_REGNO));
+ lab = gen_label_rtx ();
+ emit_insn (gen_load_toc_v4_PIC_1b (tocsym, lab));
+ emit_move_insn (dest, gen_rtx_REG (Pmode, LR_REGNO));
emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
}
emit_insn (gen_addsi3 (dest, temp0, dest));
Index: gcc/config/rs6000/rs6000.md
===================================================================
--- gcc/config/rs6000/rs6000.md (revision 160024)
+++ gcc/config/rs6000/rs6000.md (working copy)
@@ -11436,10 +11588,12 @@ (define_insn "load_toc_v4_PIC_1"
(define_insn "load_toc_v4_PIC_1b"
[(set (reg:SI LR_REGNO)
- (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")]
- UNSPEC_TOCPTR))]
+ (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
+ (label_ref (match_operand 1 "" ""))]
+ UNSPEC_TOCPTR))
+ (match_dup 1)]
"TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2"
- "bcl 20,31,$+8\\n\\t.long %0-$"
+ "bcl 20,31,$+8\;.long %0-$"
[(set_attr "type" "branch")
(set_attr "length" "8")])
--
Alan Modra
Australia Development Lab, IBM