From patchwork Tue Jun 3 19:56:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 355633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9312A14008D for ; Wed, 4 Jun 2014 05:57:07 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:message-id:in-reply-to:subject:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=pT7 f2vP1bDXtyG9VburkKQ5zKbtoAxwBdA+Py0eJA6Ua81ppkwsNLPwhmW4Fq1YP57m Ajhl20qfwDTCWG83FLPSZTssnoAtnqogRkyt5Z0RLSpmVKE/uVkI+SyKmHJXCB/s JzNl+RO4q8OmN+XysAkyyPysK8gasFgaCczwyJbk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:message-id:in-reply-to:subject:mime-version :content-type:content-transfer-encoding; s=default; bh=/w+rUpShn GnxMqBEz1nFAawb9JY=; b=DxYwF5eQmH2/vupLs3G4atWe6BEg2YAFetPRJghrz z9yc9ZXkRn4VcuxrihTRxzcBsalmY/4GTjDBqb/QZz5nEXjCANA5WN5B8qnwuZN2 jB7OcgpA1nUZbqxWOyJCO9QGwu8hmX5zTqLIE6aclHq4ewYoCSkX3tMBHO75BOP9 cU= Received: (qmail 2350 invoked by alias); 3 Jun 2014 19:57:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2338 invoked by uid 89); 3 Jun 2014 19:57:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx3-phx2.redhat.com Received: from mx3-phx2.redhat.com (HELO mx3-phx2.redhat.com) (209.132.183.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jun 2014 19:56:58 +0000 Received: from zmail14.collab.prod.int.phx2.redhat.com (zmail14.collab.prod.int.phx2.redhat.com [10.5.83.16]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s53JuvWo022940; Tue, 3 Jun 2014 15:56:57 -0400 Date: Tue, 3 Jun 2014 15:56:57 -0400 (EDT) From: Kai Tietz To: GCC Patches Cc: Richard Henderson , Jeff Law Message-ID: <1705189073.20810228.1401825417250.JavaMail.zimbra@redhat.com> In-Reply-To: <1573472454.20807126.1401825307070.JavaMail.zimbra@redhat.com> Subject: [patch i386]: Fix PR/46219 Generate indirect jump instruction MIME-Version: 1.0 X-IsSubscribed: yes Hello, This patch fixes PR/46219 by introducing special peephole-optimization. As we can't set for new statement in peephole2-define SIBLING_CALL_P easily, I use UNSPEC_PEEPSIB to do indentify sibling tail-call-case. For avoiding modification of ix86_output_call_insn, I set SIBLING_CALL_P directly before outputing it. If it is preferred we can modify here instead ix86_output_call_insn to allow forcing to output sibcall on demand. ChangeLog 2014-06-03 Kai Tietz PR target/46219 * config/i386/i386.md (UNSPEC_PEEPSIB): New unspec. (sibcall_intern): New define-insn to handle UNSPEC_PEEPSIB. (sibcall_pop_intern): Likewise. (sibcall_value_intern): Likewise. (sibcall_value_pop_intern): Likewise. (define_peephole2): Simple combine for sibling-tail-call. ChangeLog 2014-06-03 Kai Tietz PR target/46219 * gcc.target/i386/sibcall-4.c: Remove xfail. Tested patch for x86_64-unknown-linux-gnu, and i686-pc-cygwin. Ok for apply? Regards, Kai Index: config/i386/i386.md =================================================================== --- config/i386/i386.md (revision 211198) +++ config/i386/i386.md (working copy) @@ -111,6 +111,7 @@ UNSPEC_LEA_ADDR UNSPEC_XBEGIN_ABORT UNSPEC_STOS + UNSPEC_PEEPSIB ;; For SSE/MMX support: UNSPEC_FIX_NOTRUNC @@ -11382,6 +11383,54 @@ "* 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))] + "" + "* SIBLING_CALL_P (insn) = 1; return ix86_output_call_insn (insn, operands[0]);" + [(set_attr "type" "call")]) + +; TODO +(define_peephole2 + [(set (match_operand:DI 0 "register_operand") + (match_operand:DI 1 "memory_operand")) + (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)] + "TARGET_64BIT" + [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) + (set (match_dup 0) + (match_dup 1))]) + +(define_peephole2 + [(set (match_operand:SI 0 "register_operand") + (match_operand:SI 1 "memory_operand")) + (unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)] + "!TARGET_64BIT" + [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE) + (set (match_dup 0) + (match_dup 1))]) + +(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: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_expand "call_pop" [(parallel [(call (match_operand:QI 0) (match_operand:SI 1)) @@ -11415,6 +11464,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" + "* SIBLING_CALL_P (insn) = 1; 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 +11516,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)))] + "" + "* SIBLING_CALL_P (insn) = 1; 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 +11570,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" + "* SIBLING_CALL_P (insn) = 1; return ix86_output_call_insn (insn, operands[1]);" + [(set_attr "type" "callv")]) + ;; Call subroutine returning any type. (define_expand "untyped_call" Index: testsuite/gcc.target/i386/sibcall-4.c =================================================================== --- testsuite/gcc.target/i386/sibcall-4.c (revision 211198) +++ testsuite/gcc.target/i386/sibcall-4.c (working copy) @@ -11,4 +11,4 @@ void male_indirect_jump (long offset) dispatch[offset](offset); } -/* { dg-final { scan-assembler-not "jmp\[ \t\]*.%eax" { xfail *-*-* } } } */ +/* { dg-final { scan-assembler-not "jmp\[ \t\]*.%eax" } } */