diff mbox

[i386] : Fix PR/46219 Generate indirect jump instruction

Message ID CAEwic4b5ihc7dPLWg8No++DwgNtLW1=Jfkk1Dvqnf4DyH==syA@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz June 4, 2014, 12:37 p.m. UTC
So after SIBLING_CALL_P flags gets now preserved in peep2_attempt, the
patch simplifies.

Regression tested for x86_64-unknown-linux-gnu, and i686-pc-cygwin.
Ok for apply (with ChangeLog plus testcase adjustment as done by
initial patch)?

             (match_operand:SI 1))
@@ -11415,6 +11471,16 @@
   "* return ix86_output_call_insn (insn, operands[0]);"
   [(set_attr "type" "call")])

+(define_insn "*sibcall_pop_intern"
+  [(call (unspec [(mem:QI (match_operand:SI 0 "memory_operand"))]
UNSPEC_PEEPSIB)
+     (match_operand 1))
+   (set (reg:SI SP_REG)
+    (plus:SI (reg:SI SP_REG)
+         (match_operand:SI 2 "immediate_operand" "i")))]
+  "!TARGET_64BIT"
+  "* return ix86_output_call_insn (insn, operands[0]);"
+  [(set_attr "type" "call")])
+
 ;; Call subroutine, returning value in operand 0

 (define_expand "call_value"
@@ -11457,6 +11523,14 @@
   "* return ix86_output_call_insn (insn, operands[1]);"
   [(set_attr "type" "callv")])

+(define_insn "*sibcall_value_intern"
+  [(set (match_operand 0)
+    (call (unspec [(mem:QI (match_operand:W 1 "memory_operand"))]
UNSPEC_PEEPSIB)
+          (match_operand 2)))]
+  ""
+  "* return ix86_output_call_insn (insn, operands[1]);"
+  [(set_attr "type" "callv")])
+
 (define_insn "*call_value_rex64_ms_sysv"
   [(match_parallel 3 "call_rex64_ms_sysv_operation"
     [(set (match_operand 0)
@@ -11503,6 +11577,17 @@
   "* return ix86_output_call_insn (insn, operands[1]);"
   [(set_attr "type" "callv")])

+(define_insn "*sibcall_value_pop_intern"
+  [(set (match_operand 0)
+        (call (unspec [(mem:QI (match_operand:SI 1
"memory_operand"))] UNSPEC_PEEPSIB)
+          (match_operand 2)))
+   (set (reg:SI SP_REG)
+    (plus:SI (reg:SI SP_REG)
+         (match_operand:SI 3 "immediate_operand" "i")))]
+  "!TARGET_64BIT"
+  "* return ix86_output_call_insn (insn, operands[1]);"
+  [(set_attr "type" "callv")])
+
 ;; Call subroutine returning any type.

 (define_expand "untyped_call"

Comments

Richard Henderson June 4, 2014, 7:59 p.m. UTC | #1
On 06/04/2014 05:37 AM, Kai Tietz wrote:
> +(define_peephole2
> +  [(set (match_operand:DI 0 "register_operand")
> +        (match_operand:DI 1 "memory_operand"))
> +   (call (mem:QI (match_operand:DI 2 "register_operand"))
> +         (match_operand 3))]
> +  "TARGET_64BIT  && REG_P (operands[0])
> +    && REG_P (operands[2])
> +    && SIBLING_CALL_P (peep2_next_insn (1))
> +    && REGNO (operands[0]) == REGNO (operands[2])"
> +  [(call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) (match_dup 3))])

You can use (match_dup 0) instead of that (match_operand 2);
that allows you to remove

 +    && REG_P (operands[2])
 +    && REGNO (operands[0]) == REGNO (operands[2])"

You don't need the

 +    && REG_P (operands[2])

because of the register_operand constraint; all subregs will have been resolved
at this point.

You need a !TARGET_X32 check for your TARGET_64BIT patches, since the jmpq insn
always reads 64-bits.

> +(define_insn "*sibcall_pop_intern"
> +  [(call (unspec [(mem:QI (match_operand:SI 0 "memory_operand"))]
> UNSPEC_PEEPSIB)

Watch your line length (and line-wrapping when posting patches).
Align the UNSPEC_PEEPSIB with the [.

This, and the other following sibcall intern patterns, including

> +(define_insn "*sibcall_value_intern"
> +(define_insn "*sibcall_value_pop_intern"

have no matching peephole2 patterns, and so will never be generated.
You'll need more peep2's.


r~
diff mbox

Patch

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md    (Revision 211212)
+++ config/i386/i386.md    (Arbeitskopie)
@@ -111,6 +111,7 @@ 
   UNSPEC_LEA_ADDR
   UNSPEC_XBEGIN_ABORT
   UNSPEC_STOS
+  UNSPEC_PEEPSIB

   ;; For SSE/MMX support:
   UNSPEC_FIX_NOTRUNC
@@ -11382,6 +11383,61 @@ 
   "* return ix86_output_call_insn (insn, operands[0]);"
   [(set_attr "type" "call")])

+(define_insn "*sibcall_intern"
+  [(call (unspec [(mem:QI (match_operand:W 0 "memory_operand"))]
UNSPEC_PEEPSIB)
+     (match_operand 1))]
+  ""
+  "* return ix86_output_call_insn (insn, operands[0]);"
+  [(set_attr "type" "call")])
+
+(define_peephole2
+  [(set (match_operand:DI 0 "register_operand")
+        (match_operand:DI 1 "memory_operand"))
+   (call (mem:QI (match_operand:DI 2 "register_operand"))
+         (match_operand 3))]
+  "TARGET_64BIT  && REG_P (operands[0])
+    && REG_P (operands[2])
+    && SIBLING_CALL_P (peep2_next_insn (1))
+    && REGNO (operands[0]) == REGNO (operands[2])"
+  [(call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) (match_dup 3))])
+
+(define_peephole2
+  [(set (match_operand:DI 0 "register_operand")
+        (match_operand:DI 1 "memory_operand"))
+   (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (call (mem:QI (match_operand:DI 2 "register_operand"))
+         (match_operand 3))]
+  "TARGET_64BIT  && REG_P (operands[0])
+    && REG_P (operands[2])
+    && SIBLING_CALL_P (peep2_next_insn (2))
+    && REGNO (operands[0]) == REGNO (operands[2])"
+  [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) (match_dup 3))])
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand")
+        (match_operand:SI 1 "memory_operand"))
+   (call (mem:QI (match_operand:SI 2 "register_operand"))
+         (match_operand 3))]
+  "!TARGET_64BIT  && REG_P (operands[0])
+    && REG_P (operands[2])
+    && SIBLING_CALL_P (peep2_next_insn (1))
+    && REGNO (operands[0]) == REGNO (operands[2])"
+  [(call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) (match_dup 3))])
+
+(define_peephole2
+  [(set (match_operand:SI 0 "register_operand")
+        (match_operand:SI 1 "memory_operand"))
+   (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (call (mem:QI (match_operand:SI 2 "register_operand"))
+         (match_operand 3))]
+  "!TARGET_64BIT  && REG_P (operands[0])
+    && REG_P (operands[2])
+    && SIBLING_CALL_P (peep2_next_insn (2))
+    && REGNO (operands[0]) == REGNO (operands[2])"
+  [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
+   (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) (match_dup 3))])
+
 (define_expand "call_pop"
   [(parallel [(call (match_operand:QI 0)