From patchwork Tue Nov 13 12:49:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 997082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489877-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Idg0cN5m"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gd//YrDB"; dkim-atps=neutral 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 42vSBJ0wX4z9s9G for ; Tue, 13 Nov 2018 23:49:27 +1100 (AEDT) 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:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=IT7ObivLCfoN35uhL zjgt2EbUusZFGqJ/19vITUyrbD5Fzy3MODQeoXMJVJN3vAJHT+9LiVblGheaMnpt e5ZS7JfLIcVm0E6aiZzJPs3V/WREEE/hBOG/XATSxkCJYxymyDOjYPN1C8nZ6Vto lKVwztAPb4h82Y9jxNGy7tc2Og= 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:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=NddRMurPv8Cd9SxjujwkW9G qukg=; b=Idg0cN5mD7CpiVMa+FNkc80Y1EQjSqfRQfUGX8VJnugsRLsIixmFtlp rgW21wzBqVFkSZr+HqcRz2E76NbmHM/+39HxSKy1xv8PzOW99W4UerBZFvbMdhbe j9WpjrtjzgYFrYbL+Tjcwygr0LgovmXX27noH0gg8XpZKDt2DFKY= Received: (qmail 61873 invoked by alias); 13 Nov 2018 12:49:14 -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 61686 invoked by uid 89); 13 Nov 2018 12:49:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pf1-f176.google.com Received: from mail-pf1-f176.google.com (HELO mail-pf1-f176.google.com) (209.85.210.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Nov 2018 12:49:09 +0000 Received: by mail-pf1-f176.google.com with SMTP id g7-v6so5997499pfo.10 for ; Tue, 13 Nov 2018 04:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6mL0Z7X2Z8n+yREa+z//UumMa+dCn8q8nhLGr9ANpzE=; b=Gd//YrDBmzLwx9uDJiIpSCOBYihY9KHJAPYRNhbH30jAHEQPKGhVnATSbPd1GrLyRB w3/g/4yC5ua0+vtnQQSeB2ru1kbuRtDmmNzSY1k/uZeWCxL5Xs0hHsTMr4k8YlypAktN BXtit5uHAB5onN/wMf2Y6uu6NVGyq/YWMhR7C3rRDgCZ+MtvwJIOurpYBk/T7Tap/B4Z cRAbq5OLTTxsaq9SLRlJIKi0r+HxraikJCy0Yx0qMIT1i1xFo2VTE421Sr/dRRvJbuOA 24wmbkom+Oyopt7319y6aWmiiaKzuUGJ4os8skUNkW5wTvTeAxbkxheoiZ1CKTjdjnHS rr3g== Received: from bubble.grove.modra.org ([58.175.241.133]) by smtp.gmail.com with ESMTPSA id z30-v6sm10496607pfg.41.2018.11.13.04.49.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Nov 2018 04:49:07 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 49E52805EE; Tue, 13 Nov 2018 23:19:03 +1030 (ACDT) Date: Tue, 13 Nov 2018 23:19:03 +1030 From: Alan Modra To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org Subject: [PATCH 2/6] [RS6000] rs6000_indirect_call_template Message-ID: <20181113124903.GR29784@bubble.grove.modra.org> References: <20181107053326.GM29482@bubble.grove.modra.org> <20181107053751.GO29482@bubble.grove.modra.org> <2c5b2155-b4ce-b95a-8848-121c4398fb67@linux.ibm.com> <20181113001424.GD29784@bubble.grove.modra.org> <20181113111407.GP23873@gate.crashing.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20181113111407.GP23873@gate.crashing.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-IsSubscribed: yes Version 2. Like the last patch for external calls, now handle most assembly code for indirect calls in one place. The patch also merges some insns, correcting some !rs6000_speculate_indirect_jumps cases branching to LR, which don't require a speculation barrier. * config/rs6000/rs6000-protos.h (rs6000_indirect_call_template), (rs6000_indirect_sibcall_template): Declare. * config/rs6000/rs6000.c (rs6000_indirect_call_template_1), (rs6000_indirect_call_template, rs6000_indirect_sibcall_template): New functions. * config/rs6000/rs6000.md (call_indirect_nonlocal_sysv), (call_value_indirect_nonlocal_sysv, sibcall_nonlocal_sysv), (call_indirect_aix, call_value_indirect_aix): Use rs6000_indirect_call_template and rs6000_indirect_sibcall_template. call_indirect_elfv2, call_value_indirect_elfv2): Likewise, and handle both speculation and non-speculation cases. (call_indirect_aix_nospec, call_value_indirect_aix_nospec): Delete. (call_indirect_elfv2_nospec, call_value_indirect_elfv2_nospec): Delete. diff --git a/gcc/config/rs6000/rs6000-protos.h b/gcc/config/rs6000/rs6000-protos.h index 303ba7b91c3..967f65e2d94 100644 --- a/gcc/config/rs6000/rs6000-protos.h +++ b/gcc/config/rs6000/rs6000-protos.h @@ -113,6 +113,8 @@ extern void print_operand (FILE *, rtx, int); extern void print_operand_address (FILE *, rtx); extern const char *rs6000_call_template (rtx *, unsigned int, const char *); extern const char *rs6000_sibcall_template (rtx *, unsigned int, const char *); +extern const char *rs6000_indirect_call_template (rtx *, unsigned int); +extern const char *rs6000_indirect_sibcall_template (rtx *, unsigned int); extern enum rtx_code rs6000_reverse_condition (machine_mode, enum rtx_code); extern rtx rs6000_emit_eqne (machine_mode, rtx, rtx, rtx); diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 6e84f5053c2..cd1ab95166e 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -21416,6 +21416,83 @@ rs6000_sibcall_template (rtx *operands, unsigned int funop, const char *arg) return rs6000_call_template_1 (operands, funop, true, arg); } +/* As above, for indirect calls. */ + +static const char * +rs6000_indirect_call_template_1 (rtx *operands, unsigned int funop, + bool sibcall) +{ + /* -Wformat-overflow workaround, without which gcc thinks that %u + might produce 10 digits. */ + gcc_assert (funop <= MAX_RECOG_OPERANDS); + + static char str[144]; + const char *ptrload = TARGET_64BIT ? "d" : "wz"; + + /* We don't need the extra code to stop indirect call speculation if + calling via LR. */ + bool speculate = (TARGET_MACHO + || rs6000_speculate_indirect_jumps + || (REG_P (operands[funop]) + && REGNO (operands[funop]) == LR_REGNO)); + + if (DEFAULT_ABI == ABI_AIX) + { + if (speculate) + sprintf (str, + "l%s 2,%%%u\n\t" + "b%%T%ul\n\t" + "l%s 2,%%%u(1)", + ptrload, funop + 2, funop, ptrload, funop + 3); + else + sprintf (str, + "crset 2\n\t" + "l%s 2,%%%u\n\t" + "beq%%T%ul-\n\t" + "l%s 2,%%%u(1)", + ptrload, funop + 2, funop, ptrload, funop + 3); + } + else if (DEFAULT_ABI == ABI_ELFv2) + { + if (speculate) + sprintf (str, + "b%%T%ul\n\t" + "l%s 2,%%%u(1)", + funop, ptrload, funop + 2); + else + sprintf (str, + "crset 2\n\t" + "beq%%T%ul-\n\t" + "l%s 2,%%%u(1)", + funop, ptrload, funop + 2); + } + else + { + if (speculate) + sprintf (str, + "b%%T%u%s", + funop, sibcall ? "" : "l"); + else + sprintf (str, + "crset 2\n\t" + "beq%%T%u%s-%s", + funop, sibcall ? "" : "l", sibcall ? "\n\tb $" : ""); + } + return str; +} + +const char * +rs6000_indirect_call_template (rtx *operands, unsigned int funop) +{ + return rs6000_indirect_call_template_1 (operands, funop, false); +} + +const char * +rs6000_indirect_sibcall_template (rtx *operands, unsigned int funop) +{ + return rs6000_indirect_call_template_1 (operands, funop, true); +} + #if defined (HAVE_GAS_HIDDEN) && !TARGET_MACHO /* Emit an assembler directive to set symbol visibility for DECL to VISIBILITY_TYPE. */ diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index db9cfe92c72..fe904b1966b 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -10539,11 +10539,7 @@ (define_insn "*call_indirect_nonlocal_sysv" else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - if (rs6000_speculate_indirect_jumps - || which_alternative == 1 || which_alternative == 3) - return "b%T0l"; - else - return "crset 2\;beq%T0l-"; + return rs6000_indirect_call_template (operands, 0); } [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") (set_attr_alternative "length" @@ -10629,11 +10625,7 @@ (define_insn "*call_value_indirect_nonlocal_sysv" else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS) output_asm_insn ("creqv 6,6,6", operands); - if (rs6000_speculate_indirect_jumps - || which_alternative == 1 || which_alternative == 3) - return "b%T1l"; - else - return "crset 2\;beq%T1l-"; + return rs6000_indirect_call_template (operands, 1); } [(set_attr "type" "jmpreg,jmpreg,jmpreg,jmpreg") (set_attr_alternative "length" @@ -10764,21 +10756,16 @@ (define_insn "*call_indirect_aix" (use (match_operand:P 2 "memory_operand" ",")) (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" - " 2,%2\;b%T0l\; 2,%3(1)" - [(set_attr "type" "jmpreg") - (set_attr "length" "12")]) - -(define_insn "*call_indirect_aix_nospec" - [(call (mem:SI (match_operand:P 0 "register_operand" "c,*l")) - (match_operand 1 "" "g,g")) - (use (match_operand:P 2 "memory_operand" ",")) - (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 2\; 2,%2\;beq%T0l-\; 2,%3(1)" + "DEFAULT_ABI == ABI_AIX" +{ + return rs6000_indirect_call_template (operands, 0); +} [(set_attr "type" "jmpreg") - (set_attr "length" "16")]) + (set (attr "length") + (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (const_string "16") + (const_string "12")))]) (define_insn "*call_value_indirect_aix" [(set (match_operand 0 "" "") @@ -10787,22 +10774,16 @@ (define_insn "*call_value_indirect_aix" (use (match_operand:P 3 "memory_operand" ",")) (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" - " 2,%3\;b%T1l\; 2,%4(1)" - [(set_attr "type" "jmpreg") - (set_attr "length" "12")]) - -(define_insn "*call_value_indirect_aix_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" ",")) - (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 2\; 2,%3\;beq%T1l-\; 2,%4(1)" + "DEFAULT_ABI == ABI_AIX" +{ + return rs6000_indirect_call_template (operands, 1); +} [(set_attr "type" "jmpreg") - (set_attr "length" "16")]) + (set (attr "length") + (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (const_string "16") + (const_string "12")))]) ;; Call to indirect functions with the ELFv2 ABI. ;; Operand0 is the addresss of the function to call @@ -10813,21 +10794,16 @@ (define_insn "*call_indirect_elfv2" (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" - "b%T0l\; 2,%2(1)" - [(set_attr "type" "jmpreg") - (set_attr "length" "8")]) - -;; Variant with deliberate misprediction. -(define_insn "*call_indirect_elfv2_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 2\;beq%T0l-\; 2,%2(1)" + "DEFAULT_ABI == ABI_ELFv2" +{ + return rs6000_indirect_call_template (operands, 0); +} [(set_attr "type" "jmpreg") - (set_attr "length" "12")]) + (set (attr "length") + (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (const_string "12") + (const_string "8")))]) (define_insn "*call_value_indirect_elfv2" [(set (match_operand 0 "" "") @@ -10835,22 +10811,16 @@ (define_insn "*call_value_indirect_elfv2" (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" - "b%T1l\; 2,%3(1)" - [(set_attr "type" "jmpreg") - (set_attr "length" "8")]) - -; Variant with deliberate misprediction. -(define_insn "*call_value_indirect_elfv2_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 2\;beq%T1l-\; 2,%3(1)" + "DEFAULT_ABI == ABI_ELFv2" +{ + return rs6000_indirect_call_template (operands, 1); +} [(set_attr "type" "jmpreg") - (set_attr "length" "12")]) + (set (attr "length") + (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps") + (match_test "which_alternative != 1")) + (const_string "12") + (const_string "8")))]) ;; Call subroutine returning any type. (define_expand "untyped_call" @@ -11019,13 +10989,7 @@ (define_insn "*sibcall_nonlocal_sysv" output_asm_insn ("creqv 6,6,6", operands); if (which_alternative >= 2) - { - if (rs6000_speculate_indirect_jumps) - return "b%T0"; - else - /* Can use CR0 since it is volatile across sibcalls. */ - return "crset 2\;beq%T0-\;b $"; - } + return rs6000_indirect_sibcall_template (operands, 0); else return rs6000_sibcall_template (operands, 0, ""); }