Hello! Attached patch fixes recently added sibcall insns and their corresponding peephole2 patterns:
- There is no need for new memory_nox32_operand. A generic memory_operand can be used, since new insns and peephole2 patterns should be disabled for TARGET_X32 entirely. - Adds missing "m" constraint in insn patterns. - Macroizes peephole2 patterns - Adds check that eliminated register is really dead after the call (maybe an overkill, but some hard-to-debug problems surfaced due to missing liveness checks in the past) - Fixes call RTXes in sibcall_pop related patterns (and fixes two newly introduced warnings in i386.md) 2014-06-18 Uros Bizjak <ubiz...@gmail.com> * config/i386/i386.md (*sibcall_memory): Rename from *sibcall_intern. Do not use unspec as call operand. Use memory_operand instead of memory_nox32_operand and add "m" operand constraint. Disable pattern for TARGET_X32. (*sibcall_pop_memory): Ditto. (*sibcall_value_memory): Ditto. (*sibcall_value_pop_memory): Ditto. (sibcall peepholes): Merge SImode and DImode patterns using W mode iterator. Use memory_operand instead of memory_nox32_operand. Disable pattern for TARGET_X32. Check if eliminated register is really dead after call insn. Generate call RTX without unspec operand. (sibcall_value peepholes): Ditto. (sibcall_pop peepholes): Fix call insn RTXes. Use memory_operand instead of memory_nox32_operand. Check if eliminated register is really dead after call insn. Generate call RTX without unspec operand. (sibcall_value_pop peepholes): Ditto. * config/i386/predicates.md (memory_nox32_operand): Remove predicate. The patch was bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32} and was committed to mainline SVN. Uros.
Index: i386.md =================================================================== --- i386.md (revision 211725) +++ i386.md (working copy) @@ -11354,53 +11354,38 @@ "* 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_nox32_operand"))] - UNSPEC_PEEPSIB) - (match_operand 1))] - "" +(define_insn "*sibcall_memory" + [(call (mem:QI (match_operand:W 0 "memory_operand" "m")) + (match_operand 1)) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)] + "!TARGET_X32" "* 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_nox32_operand")) + [(set (match_operand:W 0 "register_operand") + (match_operand:W 1 "memory_operand")) (call (mem:QI (match_dup 0)) (match_operand 3))] - "TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" - [(call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) - (match_dup 3))]) + "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1)) + && peep2_reg_dead_p (2, operands[0])" + [(parallel [(call (mem:QI (match_dup 1)) + (match_dup 3)) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) (define_peephole2 - [(set (match_operand:DI 0 "register_operand") - (match_operand:DI 1 "memory_nox32_operand")) + [(set (match_operand:W 0 "register_operand") + (match_operand:W 1 "memory_operand")) (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) (call (mem:QI (match_dup 0)) (match_operand 3))] - "TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))" + "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2)) + && peep2_reg_dead_p (3, operands[0])" [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) - (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) - (match_dup 3))]) + (parallel [(call (mem:QI (match_dup 1)) + (match_dup 3)) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) -(define_peephole2 - [(set (match_operand:SI 0 "register_operand") - (match_operand:SI 1 "memory_nox32_operand")) - (call (mem:QI (match_dup 0)) - (match_operand 3))] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" - [(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_nox32_operand")) - (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) - (call (mem:QI (match_dup 0)) - (match_operand 3))] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (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) (match_operand:SI 1)) @@ -11434,42 +11419,52 @@ "* 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_nox32_operand"))] - UNSPEC_PEEPSIB) +(define_insn "*sibcall_pop_memory" + [(call (mem:QI (match_operand:SI 0 "memory_operand" "m")) (match_operand 1)) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) - (match_operand:SI 2 "immediate_operand" "i")))] + (match_operand:SI 2 "immediate_operand" "i"))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)] "!TARGET_64BIT" "* return ix86_output_call_insn (insn, operands[0]);" [(set_attr "type" "call")]) (define_peephole2 [(set (match_operand:SI 0 "register_operand") - (match_operand:SI 1 "memory_nox32_operand")) + (match_operand:SI 1 "memory_operand")) (parallel [(call (mem:QI (match_dup 0)) (match_operand 3)) (set (reg:SI SP_REG) - (match_operand 4))])] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" - [(parallel [(call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) + (plus:SI (reg:SI SP_REG) + (match_operand:SI 4 "immediate_operand")))])] + "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1)) + && peep2_reg_dead_p (2, operands[0])" + [(parallel [(call (mem:QI (match_dup 1)) (match_dup 3)) - (set (reg:SI SP_REG) (match_dup 4))])]) + (set (reg:SI SP_REG) + (plus:SI (reg:SI SP_REG) + (match_dup 4))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) (define_peephole2 [(set (match_operand:SI 0 "register_operand") - (match_operand:SI 1 "memory_nox32_operand")) + (match_operand:SI 1 "memory_operand")) (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) (parallel [(call (mem:QI (match_dup 0)) (match_operand 3)) (set (reg:SI SP_REG) - (match_operand 4))])] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))" + (plus:SI (reg:SI SP_REG) + (match_operand:SI 4 "immediate_operand")))])] + "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2)) + && peep2_reg_dead_p (3, operands[0])" [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) - (parallel [(call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) + (parallel [(call (mem:QI (match_dup 1)) (match_dup 3)) - (set (reg:SI SP_REG) (match_dup 4))])]) + (set (reg:SI SP_REG) + (plus:SI (reg:SI SP_REG) + (match_dup 4))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) ;; Call subroutine, returning value in operand 0 @@ -11513,63 +11508,43 @@ "* return ix86_output_call_insn (insn, operands[1]);" [(set_attr "type" "callv")]) -(define_insn "*sibcall_value_intern" +(define_insn "*sibcall_value_memory" [(set (match_operand 0) - (call (unspec [(mem:QI (match_operand:W 1 "memory_nox32_operand"))] - UNSPEC_PEEPSIB) - (match_operand 2)))] - "" + (call (mem:QI (match_operand:W 1 "memory_operand" "m")) + (match_operand 2))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)] + "!TARGET_X32" "* return ix86_output_call_insn (insn, operands[1]);" [(set_attr "type" "callv")]) (define_peephole2 - [(set (match_operand:DI 0 "register_operand") - (match_operand:DI 1 "memory_nox32_operand")) + [(set (match_operand:W 0 "register_operand") + (match_operand:W 1 "memory_operand")) (set (match_operand 2) (call (mem:QI (match_dup 0)) (match_operand 3)))] - "TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" - [(set (match_dup 2) - (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) - (match_dup 3)))]) + "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1)) + && peep2_reg_dead_p (2, operands[0])" + [(parallel [(set (match_dup 2) + (call (mem:QI (match_dup 1)) + (match_dup 3))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) (define_peephole2 - [(set (match_operand:DI 0 "register_operand") - (match_operand:DI 1 "memory_nox32_operand")) + [(set (match_operand:W 0 "register_operand") + (match_operand:W 1 "memory_operand")) (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) (set (match_operand 2) (call (mem:QI (match_dup 0)) (match_operand 3)))] - "TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))" + "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2)) + && peep2_reg_dead_p (3, operands[0])" [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) - (set (match_dup 2) - (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) - (match_dup 3)))]) + (parallel [(set (match_dup 2) + (call (mem:QI (match_dup 1)) + (match_dup 3))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) -(define_peephole2 - [(set (match_operand:SI 0 "register_operand") - (match_operand:SI 1 "memory_nox32_operand")) - (set (match_operand 2) - (call (mem:QI (match_dup 0)) - (match_operand 3)))] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" - [(set (match_dup 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_nox32_operand")) - (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) - (set (match_operand 2) - (call (mem:QI (match_dup 0)) - (match_operand 3)))] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))" - [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) - (set (match_dup 2) - (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) - (match_dup 3)))]) - (define_insn "*call_value_rex64_ms_sysv" [(match_parallel 3 "call_rex64_ms_sysv_operation" [(set (match_operand 0) @@ -11616,55 +11591,57 @@ "* return ix86_output_call_insn (insn, operands[1]);" [(set_attr "type" "callv")]) -(define_insn "*sibcall_value_pop_intern" +(define_insn "*sibcall_value_pop_memory" [(set (match_operand 0) - (call (unspec [(mem:QI (match_operand:SI 1 "memory_nox32_operand"))] - UNSPEC_PEEPSIB) + (call (mem:QI (match_operand:SI 1 "memory_operand" "m")) (match_operand 2))) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) - (match_operand:SI 3 "immediate_operand" "i")))] + (match_operand:SI 3 "immediate_operand" "i"))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)] "!TARGET_64BIT" "* return ix86_output_call_insn (insn, operands[1]);" [(set_attr "type" "callv")]) (define_peephole2 [(set (match_operand:SI 0 "register_operand") - (match_operand:SI 1 "memory_nox32_operand")) + (match_operand:SI 1 "memory_operand")) (parallel [(set (match_operand 2) (call (mem:QI (match_dup 0)) (match_operand 3))) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) - (match_operand:SI 4 "immediate_operand")))] - )] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" + (match_operand:SI 4 "immediate_operand")))])] + "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1)) + && peep2_reg_dead_p (2, operands[0])" [(parallel [(set (match_dup 2) - (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) + (call (mem:QI (match_dup 1)) (match_dup 3))) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) - (match_dup 4)))])]) + (match_dup 4))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) (define_peephole2 [(set (match_operand:SI 0 "register_operand") - (match_operand:SI 1 "memory_nox32_operand")) + (match_operand:SI 1 "memory_operand")) (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) (parallel [(set (match_operand 2) (call (mem:QI (match_dup 0)) (match_operand 3))) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) - (match_operand:SI 4 "immediate_operand")))] - )] - "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))" + (match_operand:SI 4 "immediate_operand")))])] + "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2)) + && peep2_reg_dead_p (3, operands[0])" [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) (parallel [(set (match_dup 2) - (call (unspec [(mem:QI (match_dup 1))] UNSPEC_PEEPSIB) + (call (mem:QI (match_dup 1)) (match_dup 3))) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) - (match_dup 4)))])]) + (match_dup 4))) + (unspec [(const_int 0)] UNSPEC_PEEPSIB)])]) ;; Call subroutine returning any type. Index: predicates.md =================================================================== --- predicates.md (revision 211725) +++ predicates.md (working copy) @@ -71,11 +71,10 @@ return ANY_QI_REG_P (op); }) +;; Return true if OP is a memory operands that can be used in sibcalls. (define_predicate "sibcall_memory_operand" - (match_operand 0 "memory_operand") -{ - return CONSTANT_P (XEXP (op, 0)); -}) + (and (match_operand 0 "memory_operand") + (match_test "CONSTANT_P (XEXP (op, 0))"))) ;; Match an SI or HImode register for a zero_extract. (define_special_predicate "ext_register_operand" @@ -587,11 +586,6 @@ (ior (match_operand 0 "register_no_elim_operand") (match_operand 0 "immediate_operand"))) -;; Test for a valid memory operand. -(define_predicate "memory_nox32_operand" - (and (not (match_test "TARGET_X32")) - (match_operand 0 "memory_operand"))) - ;; Test for a valid operand for indirect branch. (define_predicate "indirect_branch_operand" (ior (match_operand 0 "register_operand")