From patchwork Wed May 28 08:43:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 353280 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 111F81400CF for ; Wed, 28 May 2014 18:44:05 +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:references:subject :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=a1Dmh0+kcNZ4vCyaxMKFvGFnTN3EPK7nvrzNlTVMNsXObqEK5C96S eSkvbcyF6eH36EXBdfHOaFu3WmYDjscnj74BXsWbzj58erqHWHuMY2oXCi0Hk6jH z5AUkvuJFkVS0zb6NSK1n644yGJWRnBsriIQoQY25ikQKucIMZ5rNY= 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:references:subject :mime-version:content-type:content-transfer-encoding; s=default; bh=MN5X7zW2umy/2CnuMRGalNU/Ns0=; b=eTAUVm5dmLTqfMhLXSvr3UHNrp+t C5vsoExaNIzATe7tealA8wyXA1uezhCFYY0o7SmONBGLwMw55GecUpMcveud83iV +AaZcMlxjYzeZ1bDRNDjglY3zSp44e9UEo4Ea23WFsowwL4YOCDVT+SuLitwGy6h NarpziBWS5IZm5E= Received: (qmail 25651 invoked by alias); 28 May 2014 08:43:59 -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 25642 invoked by uid 89); 28 May 2014 08:43:58 -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, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx5-phx2.redhat.com Received: from mx5-phx2.redhat.com (HELO mx5-phx2.redhat.com) (209.132.183.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 May 2014 08:43:57 +0000 Received: from zmail14.collab.prod.int.phx2.redhat.com (zmail14.collab.prod.int.phx2.redhat.com [10.5.83.16]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4S8hujP006978; Wed, 28 May 2014 04:43:56 -0400 Date: Wed, 28 May 2014 04:43:56 -0400 (EDT) From: Kai Tietz To: Jeff Law Cc: "H.J. Lu" , GCC Patches , Jakub Jelinek , Richard Henderson Message-ID: <643791243.10265346.1401266636155.JavaMail.zimbra@redhat.com> In-Reply-To: <625132578.8474723.1401136339171.JavaMail.zimbra@redhat.com> References: <356718653.5712706.1400794422397.JavaMail.zimbra@redhat.com> <537F8DC7.3090906@redhat.com> <777706000.8424762.1401128436051.JavaMail.zimbra@redhat.com> <20140526183208.GG10386@tucnak.redhat.com> <1487116948.8449887.1401132170121.JavaMail.zimbra@redhat.com> <20140526193543.GH10386@tucnak.redhat.com> <625132578.8474723.1401136339171.JavaMail.zimbra@redhat.com> Subject: Re: [patch i386]: Expand sibling-tail-calls via accumulator register MIME-Version: 1.0 X-IsSubscribed: yes Hi, I modified prior patch so that it uses the new predicate sibcall_memory_operand to extend sibcall_insn_operand. Just one change in i386.c remains about x86_output_mi_thunk. Later one isn't pretty much essential. Nevertheless it makes code equivalent to none-memory-case for potential tail-sibcalls. ChangeLog gcc 2014-05-28 Kai Tietz * config/i386/i386.c (x86_output_mi_thunk): Add memory case for sibling-tail-calls. * config/i386/i386.md (sibcall_insn_operand): Add memory-constrain to its use. * config/i386/predicates.md (sibcall_memory_operand): New predicate. (sibcall_insn_operand): Add check for sibcall_memory_operand. ChangeLog testsuite 2014-05-28 Kai Tietz PR target/60104 * gcc.target/i386/sibcall-1.c: New test. * gcc.target/i386/sibcall-2.c: New test. * gcc.target/i386/sibcall-3.c: New test. Regression tested x86_64-unknown-linux-gnu multilib, x86_64-w64-mingw32, and i686-pc-cygwin. Ok for apply? Regards, Kai Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c (revision 210985) +++ gcc/config/i386/i386.c (working copy) @@ -38893,7 +38893,16 @@ x86_output_mi_thunk (FILE *file, For our purposes here, we can get away with (ab)using a jump pattern, because we're going to do no optimization. */ if (MEM_P (fnaddr)) - emit_jump_insn (gen_indirect_jump (fnaddr)); + { + if (sibcall_insn_operand (fnaddr, word_mode)) + { + tmp = gen_rtx_CALL (VOIDmode, fnaddr, const0_rtx); + tmp = emit_call_insn (tmp); + SIBLING_CALL_P (tmp) = 1; + } + else + emit_jump_insn (gen_indirect_jump (fnaddr)); + } else { if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr)) Index: gcc/config/i386/i386.md =================================================================== --- gcc/config/i386/i386.md (revision 210985) +++ gcc/config/i386/i386.md (working copy) @@ -11376,7 +11376,7 @@ [(set_attr "type" "call")]) (define_insn "*sibcall" - [(call (mem:QI (match_operand:W 0 "sibcall_insn_operand" "Uz")) + [(call (mem:QI (match_operand:W 0 "sibcall_insn_operand" "Uzm")) (match_operand 1))] "SIBLING_CALL_P (insn)" "* return ix86_output_call_insn (insn, operands[0]);" @@ -11406,7 +11406,7 @@ [(set_attr "type" "call")]) (define_insn "*sibcall_pop" - [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "Uz")) + [(call (mem:QI (match_operand:SI 0 "sibcall_insn_operand" "Uzm")) (match_operand 1)) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) @@ -11451,7 +11451,7 @@ (define_insn "*sibcall_value" [(set (match_operand 0) - (call (mem:QI (match_operand:W 1 "sibcall_insn_operand" "Uz")) + (call (mem:QI (match_operand:W 1 "sibcall_insn_operand" "Uzm")) (match_operand 2)))] "SIBLING_CALL_P (insn)" "* return ix86_output_call_insn (insn, operands[1]);" @@ -11494,7 +11494,7 @@ (define_insn "*sibcall_value_pop" [(set (match_operand 0) - (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "Uz")) + (call (mem:QI (match_operand:SI 1 "sibcall_insn_operand" "Uzm")) (match_operand 2))) (set (reg:SI SP_REG) (plus:SI (reg:SI SP_REG) Index: gcc/config/i386/predicates.md =================================================================== --- gcc/config/i386/predicates.md (revision 210985) +++ gcc/config/i386/predicates.md (working copy) @@ -71,6 +71,16 @@ return ANY_QI_REG_P (op); }) +(define_predicate "sibcall_memory_operand" + (match_operand 0 "memory_operand") +{ + op = XEXP (op, 0); + + if (GET_CODE (op) == CONST) + op = XEXP (op, 0); + return (GET_CODE (op) == SYMBOL_REF || CONSTANT_P (op)); +}) + ;; Match an SI or HImode register for a zero_extract. (define_special_predicate "ext_register_operand" (match_operand 0 "register_operand") @@ -600,7 +610,9 @@ (define_special_predicate "sibcall_insn_operand" (ior (match_test "constant_call_address_operand (op, mode == VOIDmode ? mode : Pmode)") - (match_operand 0 "register_no_elim_operand"))) + (match_operand 0 "register_no_elim_operand") + (and (not (match_test "TARGET_X32")) + (match_operand 0 "sibcall_memory_operand")))) ;; Return true if OP is a call from MS ABI to SYSV ABI function. (define_predicate "call_rex64_ms_sysv_operation" Index: gcc/testsuite/gcc.target/i386/sibcall-1.c =================================================================== --- gcc/testsuite/gcc.target/i386/sibcall-1.c (revision 0) +++ gcc/testsuite/gcc.target/i386/sibcall-1.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ia32 } */ +/* { dg-options "-O2" } */ + +extern int (*foo)(int); + +int boo (int a) +{ + return (*foo) (a); +} + +/* { dg-final { scan-assembler-not "mov" } } */ Index: gcc/testsuite/gcc.target/i386/sibcall-2.c =================================================================== --- gcc/testsuite/gcc.target/i386/sibcall-2.c (revision 0) +++ gcc/testsuite/gcc.target/i386/sibcall-2.c (working copy) @@ -0,0 +1,16 @@ +/* { dg-do compile { xfail { *-*-* } } } */ +/* { dg-require-effective-target ia32 } */ +/* { dg-options "-O2" } */ + +extern int doo1 (int); +extern int doo2 (int); +extern void bar (char *); + +int foo (int a) +{ + char s[256]; + bar (s); + return (a < 0 ? doo1 : doo2) (a); +} + +/* { dg-final { scan-assembler-not "call[ \t]*.%eax" } } */ Index: gcc/testsuite/gcc.target/i386/sibcall-3.c =================================================================== --- gcc/testsuite/gcc.target/i386/sibcall-3.c (revision 0) +++ gcc/testsuite/gcc.target/i386/sibcall-3.c (working copy) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target ia32 } */ +/* { dg-options "-O2" } */ + +extern +#ifdef _WIN32 + __declspec (dllimport) +#endif + void foo (int a); + +void bar (int a) +{ + return foo (a); +} + +/* { dg-final { scan-assembler-not "jmp[ \t]*.%eax" } } */ Index: gcc/testsuite/gcc.target/i386/sibcall-4.c =================================================================== --- gcc/testsuite/gcc.target/i386/sibcall-4.c (revision 0) +++ gcc/testsuite/gcc.target/i386/sibcall-4.c (working copy) @@ -0,0 +1,15 @@ +/* Testcase for PR target/46219. */ +/* { dg-do compile { xfail { *-*-* } } */ +/* { dg-require-effective-target ia32 } */ +/* { dg-options "-O2" } */ + +typedef void (*dispatch_t)(long offset); + +dispatch_t dispatch[256]; + +void male_indirect_jump (long offset) +{ + dispatch[offset](offset); +} + +/* { dg-final { scan-assembler-not "jmp[ \t]*.%eax" } } */