summaryrefslogtreecommitdiff
path: root/gcc/config/rs6000/rs6000.md
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/config/rs6000/rs6000.md')
-rw-r--r--gcc/config/rs6000/rs6000.md263
1 files changed, 243 insertions, 20 deletions
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index fe6653628c05..6daa7a99cd2c 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -11002,10 +11002,35 @@
else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
output_asm_insn ("creqv 6,6,6", operands);
- return "b%T0l";
+ if (rs6000_speculate_indirect_jumps
+ || which_alternative == 1 || which_alternative == 3)
+ return "b%T0l";
+ else
+ return "crset eq\;beq%T0l-";
}
[(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
- (set_attr "length" "4,4,8,8")])
+ (set (attr "length")
+ (cond [(and (eq (symbol_ref "which_alternative") (const_int 0))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "4")
+ (and (eq (symbol_ref "which_alternative") (const_int 0))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "8")
+ (eq (symbol_ref "which_alternative") (const_int 1))
+ (const_string "4")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "8")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "12")
+ (eq (symbol_ref "which_alternative") (const_int 3))
+ (const_string "8")]
+ (const_string "4")))])
(define_insn_and_split "*call_nonlocal_sysv<mode>"
[(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
@@ -11090,10 +11115,35 @@
else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
output_asm_insn ("creqv 6,6,6", operands);
- return "b%T1l";
+ if (rs6000_speculate_indirect_jumps
+ || which_alternative == 1 || which_alternative == 3)
+ return "b%T1l";
+ else
+ return "crset eq\;beq%T1l-";
}
[(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg")
- (set_attr "length" "4,4,8,8")])
+ (set (attr "length")
+ (cond [(and (eq (symbol_ref "which_alternative") (const_int 0))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "4")
+ (and (eq (symbol_ref "which_alternative") (const_int 0))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "8")
+ (eq (symbol_ref "which_alternative") (const_int 1))
+ (const_string "4")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "8")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "12")
+ (eq (symbol_ref "which_alternative") (const_int 3))
+ (const_string "8")]
+ (const_string "4")))])
(define_insn_and_split "*call_value_nonlocal_sysv<mode>"
[(set (match_operand 0 "" "")
@@ -11218,11 +11268,22 @@
(use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
(set (reg:P TOC_REGNUM) (unspec [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
(clobber (reg:P LR_REGNO))]
- "DEFAULT_ABI == ABI_AIX"
+ "DEFAULT_ABI == ABI_AIX && rs6000_speculate_indirect_jumps"
"<ptrload> 2,%2\;b%T0l\;<ptrload> 2,%3(1)"
[(set_attr "type" "jmpreg")
(set_attr "length" "12")])
+(define_insn "*call_indirect_aix<mode>_nospec"
+ [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
+ (match_operand 1 "" "g,g"))
+ (use (match_operand:P 2 "memory_operand" "<ptrm>,<ptrm>"))
+ (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
+ (clobber (reg:P LR_REGNO))]
+ "DEFAULT_ABI == ABI_AIX && !rs6000_speculate_indirect_jumps"
+ "crset eq\;<ptrload> 2,%2\;beq%T0l-\;<ptrload> 2,%3(1)"
+ [(set_attr "type" "jmpreg")
+ (set_attr "length" "16")])
+
(define_insn "*call_value_indirect_aix<mode>"
[(set (match_operand 0 "" "")
(call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
@@ -11230,11 +11291,23 @@
(use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
(set (reg:P TOC_REGNUM) (unspec [(match_operand:P 4 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
(clobber (reg:P LR_REGNO))]
- "DEFAULT_ABI == ABI_AIX"
+ "DEFAULT_ABI == ABI_AIX && rs6000_speculate_indirect_jumps"
"<ptrload> 2,%3\;b%T1l\;<ptrload> 2,%4(1)"
[(set_attr "type" "jmpreg")
(set_attr "length" "12")])
+(define_insn "*call_value_indirect_aix<mode>_nospec"
+ [(set (match_operand 0 "" "")
+ (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
+ (match_operand 2 "" "g,g")))
+ (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>"))
+ (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
+ (clobber (reg:P LR_REGNO))]
+ "DEFAULT_ABI == ABI_AIX && !rs6000_speculate_indirect_jumps"
+ "crset eq\;<ptrload> 2,%3\;beq%T1l-\;<ptrload> 2,%4(1)"
+ [(set_attr "type" "jmpreg")
+ (set_attr "length" "16")])
+
;; Call to indirect functions with the ELFv2 ABI.
;; Operand0 is the addresss of the function to call
;; Operand2 is the offset of the stack location holding the current TOC pointer
@@ -11244,22 +11317,44 @@
(match_operand 1 "" "g,g"))
(set (reg:P TOC_REGNUM) (unspec [(match_operand:P 2 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
(clobber (reg:P LR_REGNO))]
- "DEFAULT_ABI == ABI_ELFv2"
+ "DEFAULT_ABI == ABI_ELFv2 && rs6000_speculate_indirect_jumps"
"b%T0l\;<ptrload> 2,%2(1)"
[(set_attr "type" "jmpreg")
(set_attr "length" "8")])
+;; Variant with deliberate misprediction.
+(define_insn "*call_indirect_elfv2<mode>_nospec"
+ [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l"))
+ (match_operand 1 "" "g,g"))
+ (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 2 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
+ (clobber (reg:P LR_REGNO))]
+ "DEFAULT_ABI == ABI_ELFv2 && !rs6000_speculate_indirect_jumps"
+ "crset eq\;beq%T0l-\;<ptrload> 2,%2(1)"
+ [(set_attr "type" "jmpreg")
+ (set_attr "length" "12")])
+
(define_insn "*call_value_indirect_elfv2<mode>"
[(set (match_operand 0 "" "")
(call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
(match_operand 2 "" "g,g")))
(set (reg:P TOC_REGNUM) (unspec [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
(clobber (reg:P LR_REGNO))]
- "DEFAULT_ABI == ABI_ELFv2"
+ "DEFAULT_ABI == ABI_ELFv2 && rs6000_speculate_indirect_jumps"
"b%T1l\;<ptrload> 2,%3(1)"
[(set_attr "type" "jmpreg")
(set_attr "length" "8")])
+; Variant with deliberate misprediction.
+(define_insn "*call_value_indirect_elfv2<mode>_nospec"
+ [(set (match_operand 0 "" "")
+ (call (mem:SI (match_operand:P 1 "register_operand" "c,*l"))
+ (match_operand 2 "" "g,g")))
+ (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n")] UNSPEC_TOCSLOT))
+ (clobber (reg:P LR_REGNO))]
+ "DEFAULT_ABI == ABI_ELFv2 && !rs6000_speculate_indirect_jumps"
+ "crset eq\;beq%T1l-\;<ptrload> 2,%3(1)"
+ [(set_attr "type" "jmpreg")
+ (set_attr "length" "12")])
;; Call subroutine returning any type.
(define_expand "untyped_call"
@@ -11436,7 +11531,13 @@
output_asm_insn (\"creqv 6,6,6\", operands);
if (which_alternative >= 2)
- return \"b%T0\";
+ {
+ if (rs6000_speculate_indirect_jumps)
+ return \"b%T0\";
+ else
+ /* Can use CR0 since it is volatile across sibcalls. */
+ return \"crset eq\;beq%T0-\;b .\";
+ }
else if (DEFAULT_ABI == ABI_V4 && flag_pic)
{
gcc_assert (!TARGET_SECURE_PLT);
@@ -11446,7 +11547,28 @@
return \"b %z0\";
}"
[(set_attr "type" "branch")
- (set_attr "length" "4,8,4,8")])
+ (set (attr "length")
+ (cond [(eq (symbol_ref "which_alternative") (const_int 0))
+ (const_string "4")
+ (eq (symbol_ref "which_alternative") (const_int 1))
+ (const_string "8")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "4")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "12")
+ (and (eq (symbol_ref "which_alternative") (const_int 3))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "8")
+ (and (eq (symbol_ref "which_alternative") (const_int 3))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "16")]
+ (const_string "4")))])
(define_insn "*sibcall_value_nonlocal_sysv<mode>"
[(set (match_operand 0 "" "")
@@ -11466,7 +11588,13 @@
output_asm_insn (\"creqv 6,6,6\", operands);
if (which_alternative >= 2)
- return \"b%T1\";
+ {
+ if (rs6000_speculate_indirect_jumps)
+ return \"b%T1\";
+ else
+ /* Can use CR0 since it is volatile across sibcalls. */
+ return \"crset eq\;beq%T1-\;b .\";
+ }
else if (DEFAULT_ABI == ABI_V4 && flag_pic)
{
gcc_assert (!TARGET_SECURE_PLT);
@@ -11476,7 +11604,28 @@
return \"b %z1\";
}"
[(set_attr "type" "branch")
- (set_attr "length" "4,8,4,8")])
+ (set (attr "length")
+ (cond [(eq (symbol_ref "which_alternative") (const_int 0))
+ (const_string "4")
+ (eq (symbol_ref "which_alternative") (const_int 1))
+ (const_string "8")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "4")
+ (and (eq (symbol_ref "which_alternative") (const_int 2))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "12")
+ (and (eq (symbol_ref "which_alternative") (const_int 3))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 1)))
+ (const_string "8")
+ (and (eq (symbol_ref "which_alternative") (const_int 3))
+ (eq (symbol_ref "rs6000_speculate_indirect_jumps")
+ (const_int 0)))
+ (const_string "16")]
+ (const_string "4")))])
;; AIX ABI sibling call patterns.
@@ -12852,16 +13001,35 @@
[(set_attr "type" "jmpreg")])
(define_expand "indirect_jump"
- [(set (pc) (match_operand 0 "register_operand" ""))])
+ [(set (pc) (match_operand 0 "register_operand"))]
+ ""
+{
+ if (!rs6000_speculate_indirect_jumps) {
+ rtx ccreg = gen_reg_rtx (CCmode);
+ if (Pmode == DImode)
+ emit_jump_insn (gen_indirect_jumpdi_nospec (operands[0], ccreg));
+ else
+ emit_jump_insn (gen_indirect_jumpsi_nospec (operands[0], ccreg));
+ DONE;
+ }
+})
(define_insn "*indirect_jump<mode>"
[(set (pc) (match_operand:P 0 "register_operand" "c,*l"))]
- ""
+ "rs6000_speculate_indirect_jumps"
"@
bctr
blr"
[(set_attr "type" "jmpreg")])
+(define_insn "indirect_jump<mode>_nospec"
+ [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))
+ (clobber (match_operand:CC 1 "cc_reg_operand" "=y,y"))]
+ "!rs6000_speculate_indirect_jumps"
+ "crset %E1\;beq%T0- %1\;b ."
+ [(set_attr "type" "jmpreg")
+ (set_attr "length" "12")])
+
;; Table jump for switch statements:
(define_expand "tablejump"
[(use (match_operand 0 "" ""))
@@ -12869,10 +13037,23 @@
""
"
{
- if (TARGET_32BIT)
- emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
+ if (rs6000_speculate_indirect_jumps)
+ {
+ if (TARGET_32BIT)
+ emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
+ else
+ emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
+ }
else
- emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
+ {
+ rtx ccreg = gen_reg_rtx (CCmode);
+ rtx jump;
+ if (TARGET_32BIT)
+ jump = gen_tablejumpsi_nospec (operands[0], operands[1], ccreg);
+ else
+ jump = gen_tablejumpdi_nospec (operands[0], operands[1], ccreg);
+ emit_jump_insn (jump);
+ }
DONE;
}")
@@ -12882,13 +13063,28 @@
(match_dup 2)))
(parallel [(set (pc) (match_dup 3))
(use (label_ref (match_operand 1 "" "")))])]
- "TARGET_32BIT"
+ "TARGET_32BIT && rs6000_speculate_indirect_jumps"
"
{ operands[0] = force_reg (SImode, operands[0]);
operands[2] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
operands[3] = gen_reg_rtx (SImode);
}")
+(define_expand "tablejumpsi_nospec"
+ [(set (match_dup 4)
+ (plus:SI (match_operand:SI 0)
+ (match_dup 3)))
+ (parallel [(set (pc)
+ (match_dup 4))
+ (use (label_ref (match_operand 1)))
+ (clobber (match_operand 2))])]
+ "TARGET_32BIT && !rs6000_speculate_indirect_jumps"
+{
+ operands[0] = force_reg (SImode, operands[0]);
+ operands[3] = force_reg (SImode, gen_rtx_LABEL_REF (SImode, operands[1]));
+ operands[4] = gen_reg_rtx (SImode);
+})
+
(define_expand "tablejumpdi"
[(set (match_dup 4)
(sign_extend:DI (match_operand:SI 0 "lwa_operand" "")))
@@ -12897,23 +13093,50 @@
(match_dup 2)))
(parallel [(set (pc) (match_dup 3))
(use (label_ref (match_operand 1 "" "")))])]
- "TARGET_64BIT"
+ "TARGET_64BIT && rs6000_speculate_indirect_jumps"
"
{ operands[2] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
operands[3] = gen_reg_rtx (DImode);
operands[4] = gen_reg_rtx (DImode);
}")
+(define_expand "tablejumpdi_nospec"
+ [(set (match_dup 5)
+ (sign_extend:DI (match_operand:SI 0 "lwa_operand")))
+ (set (match_dup 4)
+ (plus:DI (match_dup 5)
+ (match_dup 3)))
+ (parallel [(set (pc)
+ (match_dup 4))
+ (use (label_ref (match_operand 1)))
+ (clobber (match_operand 2))])]
+ "TARGET_64BIT && !rs6000_speculate_indirect_jumps"
+{
+ operands[3] = force_reg (DImode, gen_rtx_LABEL_REF (DImode, operands[1]));
+ operands[4] = gen_reg_rtx (DImode);
+ operands[5] = gen_reg_rtx (DImode);
+})
+
(define_insn "*tablejump<mode>_internal1"
[(set (pc)
(match_operand:P 0 "register_operand" "c,*l"))
(use (label_ref (match_operand 1 "" "")))]
- ""
+ "rs6000_speculate_indirect_jumps"
"@
bctr
blr"
[(set_attr "type" "jmpreg")])
+(define_insn "*tablejump<mode>_internal1_nospec"
+ [(set (pc)
+ (match_operand:P 0 "register_operand" "c,*l"))
+ (use (label_ref (match_operand 1)))
+ (clobber (match_operand:CC 2 "cc_reg_operand" "=y,y"))]
+ "!rs6000_speculate_indirect_jumps"
+ "crset %E2\;beq%T0- %2\;b ."
+ [(set_attr "type" "jmpreg")
+ (set_attr "length" "12")])
+
(define_insn "nop"
[(unspec [(const_int 0)] UNSPEC_NOP)]
""