Commit 61ee0966 by Alan Modra Committed by Alan Modra

[RS6000] PR88614, output_operand: invalid %z value

The direct cause of this PR is the fact that tls_gdld_nomark didn't
handle indirect calls.  Also, most indirect calls were being optimised
back to direct calls anyway, due to tls_gdld_nomark not checking any
of the parallel elements except the first (plus the extra element that
distinguishes this call from normal calls).  There were other unwanted
substitutions too.

So this patch attacks the problem of handling special calls in a
different way.  Rather than adding another element to the call insn
parallel to distinguish -mno-tls-markers __tls_get_addr calls from any
other calls, we now inspect the second CALL arg.  Each
call_value_nonlocal and call_value_indirect insn now checks for the
tlsgd/ld unspecs when !TARGET_TLS_MARKERS and emits the arg setup
insns.  I disallow the local call patterns since we'll only see local
calls to __tls_get_addr in testcases, and it doesn't seem a good idea
to complicate the patterns just for a minor optimisation.  Sibling
call insns aren't used for libcalls, so none of these insns need to
change.

The patch also fixes a minor problem with -mno-tls-markers
__tls_get_addr calls causing a "li 3,0" instruction to be emitted
prior to the arg setup instructions, due to using a libcall with one
arg.  That isn't correct when the call insn itself sets up its arg.
Also, I've tidied the V4 secure-plt calls, generating them in
rs6000_call_sysv rather than by splitting in rs6000.md.  The
CALL_INSN_FUNCTION_USAGE added in edit_tls_call_insn is no longer
needed (since git commit 0a4b5c66df9).

On the subject of unwanted substitutions, I also saw a
_GLOBAL_OFFSET_TABLE_ symbol_ref being substituted for the GOT reg,
resulting in code like "addi 3,_GLOBAL_OFFSET_TABLE_,tls_ld@got@tlsld".
Fixed by the unspec_tls change.

	PR target/88614
	* config/rs6000/predicates.md (unspec_tls): Ensure GOT reg
	stays a reg.  Allow a const_int.
	* config/rs6000/rs6000-protos.h (rs6000_output_tlsargs): Declare.
	* config/rs6000/rs6000.h (IS_V4_FP_ARGS): Define.
	(IS_NOMARK_TLSGETADDR): Define.
	* config/rs6000/rs6000.c (edit_tls_call_insn): Delete.
	(rs6000_output_tlsargs): New function.
	(rs6000_legitimize_tls_address): Don't say a !TARGET_TLS_MARKERS
	__tls_get_addr call takes an arg.
	(rs6000_call_sysv): Generate sysv4 secure plt call pattern here..
	* config/rs6000/rs6000.md (call_nonlocal_sysv): ..rather than here,
	delete split..
	(call_value_nonlocal_sysv): ..or here, delete split.
	(tls_gdld_nomark): Delete.
	(call_value_indirect_nonlocal_sysv): Use unspec_tls as operand2
	predicate.  Call rs6000_output_tlsargs.  Adjust length to suit.
	(call_value_nonlocal_sysv): Likewise.
	(call_value_nonlocal_sysv_secure): Likewise.
	(call_value_nonlocal_aix): Likewise.
	(call_value_indirect_aix): Likewise.
	(call_value_indirect_elfv2): Likewise.
	(call_value_local32, call_value_local64): Disable for no-mark tls.
	(call_value_local_aix): Likewise.

From-SVN: r268135
parent 106fc1fc
2019-01-22 Alan Modra <amodra@gmail.com>
PR target/88614
* config/rs6000/predicates.md (unspec_tls): Ensure GOT reg
stays a reg. Allow a const_int.
* config/rs6000/rs6000-protos.h (rs6000_output_tlsargs): Declare.
* config/rs6000/rs6000.h (IS_V4_FP_ARGS): Define.
(IS_NOMARK_TLSGETADDR): Define.
* config/rs6000/rs6000.c (edit_tls_call_insn): Delete.
(rs6000_output_tlsargs): New function.
(rs6000_legitimize_tls_address): Don't say a !TARGET_TLS_MARKERS
__tls_get_addr call takes an arg.
(rs6000_call_sysv): Generate sysv4 secure plt call pattern here..
* config/rs6000/rs6000.md (call_nonlocal_sysv): ..rather than here,
delete split..
(call_value_nonlocal_sysv): ..or here, delete split.
(tls_gdld_nomark): Delete.
(call_value_indirect_nonlocal_sysv): Use unspec_tls as operand2
predicate. Call rs6000_output_tlsargs. Adjust length to suit.
(call_value_nonlocal_sysv): Likewise.
(call_value_nonlocal_sysv_secure): Likewise.
(call_value_nonlocal_aix): Likewise.
(call_value_indirect_aix): Likewise.
(call_value_indirect_elfv2): Likewise.
(call_value_local32, call_value_local64): Disable for no-mark tls.
(call_value_local_aix): Likewise.
2019-01-21 Uroš Bizjak <ubizjak@gmail.com> 2019-01-21 Uroš Bizjak <ubizjak@gmail.com>
PR target/88938 PR target/88938
......
...@@ -984,11 +984,18 @@ ...@@ -984,11 +984,18 @@
(and (match_code "symbol_ref") (and (match_code "symbol_ref")
(match_test "RS6000_SYMBOL_REF_TLS_P (op)"))) (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
;; Return 1 for the UNSPEC used in TLS call operands ;; Return 1 for the CONST_INT or UNSPEC second CALL operand.
;; Prevents unwanted substitution of the unspec got_reg arg.
(define_predicate "unspec_tls" (define_predicate "unspec_tls"
(match_code "unspec") (match_code "const_int,unspec")
{ {
return XINT (op, 1) == UNSPEC_TLSGD || XINT (op, 1) == UNSPEC_TLSLD; if (CONST_INT_P (op))
return 1;
if (XINT (op, 1) == UNSPEC_TLSGD)
return REG_P (XVECEXP (op, 0, 1));
if (XINT (op, 1) == UNSPEC_TLSLD)
return REG_P (XVECEXP (op, 0, 0));
return 0;
}) })
;; Return 1 if the operand, used inside a MEM, is a valid first argument ;; Return 1 if the operand, used inside a MEM, is a valid first argument
......
...@@ -141,6 +141,7 @@ extern rtx (*rs6000_legitimize_reload_address_ptr) (rtx, machine_mode, ...@@ -141,6 +141,7 @@ extern rtx (*rs6000_legitimize_reload_address_ptr) (rtx, machine_mode,
int, int, int, int *); int, int, int, int *);
extern bool rs6000_legitimate_offset_address_p (machine_mode, rtx, extern bool rs6000_legitimate_offset_address_p (machine_mode, rtx,
bool, bool); bool, bool);
extern void rs6000_output_tlsargs (rtx *);
extern rtx rs6000_find_base_term (rtx); extern rtx rs6000_find_base_term (rtx);
extern rtx rs6000_return_addr (int, rtx); extern rtx rs6000_return_addr (int, rtx);
extern void rs6000_output_symbol_ref (FILE*, rtx); extern void rs6000_output_symbol_ref (FILE*, rtx);
......
...@@ -8626,35 +8626,39 @@ rs6000_legitimize_tls_address_aix (rtx addr, enum tls_model model) ...@@ -8626,35 +8626,39 @@ rs6000_legitimize_tls_address_aix (rtx addr, enum tls_model model)
return dest; return dest;
} }
/* Mess with a call, to make it look like the tls_gdld insns when /* Output arg setup instructions for a !TARGET_TLS_MARKERS
!TARGET_TLS_MARKERS. These insns have an extra unspec to __tls_get_addr call. */
differentiate them from standard calls, because they need to emit
the arg setup insns as well as the actual call. That keeps the
arg setup insns immediately adjacent to the branch and link. */
static void void
edit_tls_call_insn (rtx arg) rs6000_output_tlsargs (rtx *operands)
{ {
rtx call_insn = last_call_insn (); /* Set up operands for output_asm_insn, without modifying OPERANDS. */
if (!TARGET_TLS_MARKERS) rtx op[3];
{
rtx patt = PATTERN (call_insn); /* The set dest of the call, ie. r3, which is also the first arg reg. */
gcc_assert (GET_CODE (patt) == PARALLEL); op[0] = operands[0];
rtvec orig = XVEC (patt, 0); /* The TLS symbol from global_tlsarg stashed as CALL operand 2. */
rtvec v = rtvec_alloc (GET_NUM_ELEM (orig) + 1); op[1] = XVECEXP (operands[2], 0, 0);
gcc_assert (GET_NUM_ELEM (orig) > 0); if (XINT (operands[2], 1) == UNSPEC_TLSGD)
/* The (set (..) (call (mem ..))). */ {
RTVEC_ELT (v, 0) = RTVEC_ELT (orig, 0); /* The GOT register. */
/* The extra unspec. */ op[2] = XVECEXP (operands[2], 0, 1);
RTVEC_ELT (v, 1) = arg; if (TARGET_CMODEL != CMODEL_SMALL)
/* All other assorted call pattern pieces. */ output_asm_insn ("addis %0,%2,%1@got@tlsgd@ha\n\t"
for (int i = 1; i < GET_NUM_ELEM (orig); i++) "addi %0,%0,%1@got@tlsgd@l", op);
RTVEC_ELT (v, i + 1) = RTVEC_ELT (orig, i); else
XVEC (patt, 0) = v; output_asm_insn ("addi %0,%2,%1@got@tlsgd", op);
} }
if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT && flag_pic) else if (XINT (operands[2], 1) == UNSPEC_TLSLD)
use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn), {
pic_offset_table_rtx); if (TARGET_CMODEL != CMODEL_SMALL)
output_asm_insn ("addis %0,%1,%&@got@tlsld@ha\n\t"
"addi %0,%0,%&@got@tlsld@l", op);
else
output_asm_insn ("addi %0,%1,%&@got@tlsld", op);
}
else
gcc_unreachable ();
} }
/* Passes the tls arg value for global dynamic and local dynamic /* Passes the tls arg value for global dynamic and local dynamic
...@@ -8757,41 +8761,36 @@ rs6000_legitimize_tls_address (rtx addr, enum tls_model model) ...@@ -8757,41 +8761,36 @@ rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
{ {
rtx arg = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, addr, got), rtx arg = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, addr, got),
UNSPEC_TLSGD); UNSPEC_TLSGD);
tga = rs6000_tls_get_addr ();
global_tlsarg = arg; global_tlsarg = arg;
rtx argreg = const0_rtx;
if (TARGET_TLS_MARKERS) if (TARGET_TLS_MARKERS)
{ {
argreg = gen_rtx_REG (Pmode, 3); rtx argreg = gen_rtx_REG (Pmode, 3);
emit_insn (gen_rtx_SET (argreg, arg)); emit_insn (gen_rtx_SET (argreg, arg));
emit_library_call_value (tga, dest, LCT_CONST, Pmode,
argreg, Pmode);
} }
else
tga = rs6000_tls_get_addr (); emit_library_call_value (tga, dest, LCT_CONST, Pmode);
emit_library_call_value (tga, dest, LCT_CONST, Pmode,
argreg, Pmode);
global_tlsarg = NULL_RTX; global_tlsarg = NULL_RTX;
edit_tls_call_insn (arg);
} }
else if (model == TLS_MODEL_LOCAL_DYNAMIC) else if (model == TLS_MODEL_LOCAL_DYNAMIC)
{ {
rtx arg = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, got), rtx arg = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, got), UNSPEC_TLSLD);
UNSPEC_TLSLD); tga = rs6000_tls_get_addr ();
tmp1 = gen_reg_rtx (Pmode);
global_tlsarg = arg; global_tlsarg = arg;
rtx argreg = const0_rtx;
if (TARGET_TLS_MARKERS) if (TARGET_TLS_MARKERS)
{ {
argreg = gen_rtx_REG (Pmode, 3); rtx argreg = gen_rtx_REG (Pmode, 3);
emit_insn (gen_rtx_SET (argreg, arg)); emit_insn (gen_rtx_SET (argreg, arg));
emit_library_call_value (tga, tmp1, LCT_CONST, Pmode,
argreg, Pmode);
} }
else
tga = rs6000_tls_get_addr (); emit_library_call_value (tga, tmp1, LCT_CONST, Pmode);
tmp1 = gen_reg_rtx (Pmode);
emit_library_call_value (tga, tmp1, LCT_CONST, Pmode,
argreg, Pmode);
global_tlsarg = NULL_RTX; global_tlsarg = NULL_RTX;
edit_tls_call_insn (arg);
if (rs6000_tls_size == 16) if (rs6000_tls_size == 16)
{ {
if (TARGET_64BIT) if (TARGET_64BIT)
...@@ -37920,9 +37919,10 @@ rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) ...@@ -37920,9 +37919,10 @@ rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie)
{ {
rtx func = func_desc; rtx func = func_desc;
rtx func_addr; rtx func_addr;
rtx call[3]; rtx call[4];
rtx insn; rtx insn;
rtx abi_reg = NULL_RTX; rtx abi_reg = NULL_RTX;
int n;
if (global_tlsarg) if (global_tlsarg)
tlsarg = global_tlsarg; tlsarg = global_tlsarg;
...@@ -37970,9 +37970,16 @@ rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie) ...@@ -37970,9 +37970,16 @@ rs6000_call_sysv (rtx value, rtx func_desc, rtx tlsarg, rtx cookie)
call[0] = gen_rtx_SET (value, call[0]); call[0] = gen_rtx_SET (value, call[0]);
call[1] = gen_rtx_USE (VOIDmode, cookie); call[1] = gen_rtx_USE (VOIDmode, cookie);
call[2] = gen_hard_reg_clobber (Pmode, LR_REGNO); n = 2;
if (TARGET_SECURE_PLT
&& flag_pic
&& GET_CODE (func_addr) == SYMBOL_REF
&& !SYMBOL_REF_LOCAL_P (func_addr))
call[n++] = gen_rtx_USE (VOIDmode, pic_offset_table_rtx);
insn = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (3, call)); call[n++] = gen_hard_reg_clobber (Pmode, LR_REGNO);
insn = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (n, call));
insn = emit_call_insn (insn); insn = emit_call_insn (insn);
if (abi_reg) if (abi_reg)
use_reg (&CALL_INSN_FUNCTION_USAGE (insn), abi_reg); use_reg (&CALL_INSN_FUNCTION_USAGE (insn), abi_reg);
...@@ -1489,6 +1489,16 @@ extern enum reg_class rs6000_constraints[RS6000_CONSTRAINT_MAX]; ...@@ -1489,6 +1489,16 @@ extern enum reg_class rs6000_constraints[RS6000_CONSTRAINT_MAX];
#define CALL_LONG 0x00000008 /* always call indirect */ #define CALL_LONG 0x00000008 /* always call indirect */
#define CALL_LIBCALL 0x00000010 /* libcall */ #define CALL_LIBCALL 0x00000010 /* libcall */
#define IS_V4_FP_ARGS(OP) \
((INTVAL (OP) & (CALL_V4_CLEAR_FP_ARGS | CALL_V4_SET_FP_ARGS)) != 0)
/* Whether OP is an UNSPEC used in !TARGET_TLS_MARKER calls. */
#define IS_NOMARK_TLSGETADDR(OP) \
(!TARGET_TLS_MARKERS \
&& GET_CODE (OP) == UNSPEC \
&& (XINT (OP, 1) == UNSPEC_TLSGD \
|| XINT (OP, 1) == UNSPEC_TLSLD))
/* We don't have prologue and epilogue functions to save/restore /* We don't have prologue and epilogue functions to save/restore
everything for most ABIs. */ everything for most ABIs. */
#define WORLD_SAVE_P(INFO) 0 #define WORLD_SAVE_P(INFO) 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment