From patchwork Wed Apr 14 21:43:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edelsohn X-Patchwork-Id: 1466428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jJhUj4lK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FLGDv21T9z9sVw for ; Thu, 15 Apr 2021 07:43:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB9B83939C07; Wed, 14 Apr 2021 21:43:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB9B83939C07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1618436602; bh=aDFjLWKrT/tFwiJZXgeRld9dD7m+FSOzPl+BG5c5qNk=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jJhUj4lK/2X+e3YTLnhawyDeRvPX700MLfY9qAuIZCaVWt/WCuiXm68t65V76FpPp 1AxLGy6K0AjulAiADQMyNYuocskWnIYsM5Dw11SvqrL0ebLMgdo3Yx/BAP1tF3Z/Sm 1emlgztJIVzstHHnoyoIoS6t3YVFsP0mggO8hsq8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 23D3F3848009 for ; Wed, 14 Apr 2021 21:43:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 23D3F3848009 Received: by mail-wr1-x436.google.com with SMTP id a4so21263659wrr.2 for ; Wed, 14 Apr 2021 14:43:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=aDFjLWKrT/tFwiJZXgeRld9dD7m+FSOzPl+BG5c5qNk=; b=XwkPhe/tDAX5TfKslp7KLcLp4sNYh6aIGxsCsESSwOoBOVW/O8Yx5kmFFBgPlafPIj YRkHEgdHZxYEknvcU4gmxHQQh/WClJMeibg0bqT7hfEEJ7SkkxT/sBGnXhGjajpxvdOe 7nFbJH4/xs0lER1ksrkoOS1VVAWvcXnNJ3ohHfr5pPPEPPXYBn8Ybi9PmqUfSZvwf99i obwGJxFjy5oYZM1PHKlmsD+T5fazmJ3EkoGAnW/6toJHlmH0sedqICl5tayhc4G40OJf 5A3uFM/+y1BGGdh9dzVynsQS7nTVu/BLOkgo+EaVvIcunJCG17ZV+Ki0OcePWB96OSxP LgfA== X-Gm-Message-State: AOAM5339eZyNfncxmJLxt5PIH7qkctcSOU9MgR8BBUWekOjBIdASKs3R UI4LIy+O1iOnHqSCS5FAWnN8Wr7vlSgiRuKmYLxAlg7cV9E= X-Google-Smtp-Source: ABdhPJz1/ajYFhAUvOBkz90hxEcvFp0o42RF6JBCYu3kTUZEd4pllZPsXJH/yFGpoiY+UDUqvbSmTpc55jLV2BIoguM= X-Received: by 2002:adf:fb8a:: with SMTP id a10mr28956752wrr.21.1618436598835; Wed, 14 Apr 2021 14:43:18 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 14 Apr 2021 17:43:06 -0400 Message-ID: Subject: [PATCH] precompute_tls_p target hook in calls.c for AIX TLS (PR 94177) To: GCC Patches X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Edelsohn via Gcc-patches From: David Edelsohn Reply-To: David Edelsohn Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" AIX uses a compiler-managed TOC for global data, including TLS symbols. The GCC TOC implementation manages the TOC entries through the constant pool. TLS symbols sometimes require a function call to obtain the TLS base pointer. The arguments to the TLS call can conflict with arguments to a normal function call if the TLS symbol is an argument in the normal call. GCC specifically checks for this situation and precomputes the TLS arguments, but the mechanism to check for this requirement utilizes legitimate_constant_p(). The necessary result of legitimate_constant_p() for correct TOC behavior and for correct TLS argument behavior is in conflict. I have tried multiple approaches to wrap the symbol in UNSPEC and tweaking legitimate_constant_p definition. The current AIX TOC implementation is too tied to force_const_mem() and the constant pool. The calls.c test is tied to both CONST and TLS. I would appreciate not being told that this is abusing the definition of CONST in GCC or that I should re-write the TOC implementation. This patch adds a new target hook precompute_tls_p() to decide if an argument should be precomputed regardless of the result from legitmate_constant_p(). If you want to consider this a hack for AIX, fine. Bootstrapped on powerpc-ibm-aix7.2.3.0. Thanks, David * gcc/calls.c (precompute_register_parameters): Additionally test targetm.precompute_tls_p to pre-compute argument. * gcc/config/rs6000/aix.h (TARGET_PRECOMPUTE_TLS_P): Define. * gcc/config/rs6000/rs6000.c (rs6000_aix_precompute_tls_p): New. * gcc/target.def (precompute_tls_p): New. diff --git a/gcc/calls.c b/gcc/calls.c index ff606204772..883d08ba5f2 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1002,7 +1002,8 @@ precompute_register_parameters (int num_actuals, struct arg_data *args, /* If the value is a non-legitimate constant, force it into a pseudo now. TLS symbols sometimes need a call to resolve. */ if (CONSTANT_P (args[i].value) - && !targetm.legitimate_constant_p (args[i].mode, args[i].value)) + && (!targetm.legitimate_constant_p (args[i].mode, args[i].value) + || targetm.precompute_tls_p (args[i].mode, args[i].value))) args[i].value = force_reg (args[i].mode, args[i].value); /* If we're going to have to load the value by parts, pull the diff --git a/gcc/config/rs6000/aix.h b/gcc/config/rs6000/aix.h index 7fccb31307b..b116e1a36bb 100644 --- a/gcc/config/rs6000/aix.h +++ b/gcc/config/rs6000/aix.h @@ -279,3 +279,4 @@ /* Use standard DWARF numbering for DWARF debugging information. */ #define RS6000_USE_DWARF_NUMBERING +#define TARGET_PRECOMPUTE_TLS_P rs6000_aix_precompute_tls_p diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 48b8efd732b..e2010035ee8 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -9608,7 +9608,8 @@ rs6000_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x) && SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0)) != 0) return true; - /* Do not place an ELF TLS symbol in the constant pool. */ + /* Allow AIX TOC TLS symbols in the constant pool, + but not ELF TLS symbols. */ return TARGET_ELF && tls_referenced_p (x); } @@ -25370,6 +25371,18 @@ rs6000_legitimate_constant_p (machine_mode mode, rtx x) return true; } +/* Implement TARGET_PRECOMPUTE_TLS_P. + + On the AIX, TLS symbols are in the TOC, which is maintained in the + constant pool. AIX TOC TLS symbols need to be pre-computed, but + must be considered legitimate constants. */ + +static bool +rs6000_aix_precompute_tls_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x) +{ + return tls_referenced_p (x); +} + ^L /* Return TRUE iff the sequence ending in LAST sets the static chain. */ diff --git a/gcc/target.def b/gcc/target.def index d7b94bd8e5d..0ebfb58fa6f 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -2715,6 +2715,18 @@ The default definition returns true.", bool, (machine_mode mode, rtx x), hook_bool_mode_rtx_true) +/* True if X is a TLS operand whose value should be pre-computed. */ +DEFHOOK +(precompute_tls_p, + "This hook returns true if @var{x} is a TLS operand on the target\n\ +machine that should be pre-computed when used as the argument in a call.\n\ +You can assume that @var{x} satisfies @code{CONSTANT_P}, so you need not \n\ +check this.\n\ +\n\ +The default definition returns false.", + bool, (machine_mode mode, rtx x), + hook_bool_mode_rtx_false) + /* True if the constant X cannot be placed in the constant pool. */ DEFHOOK (cannot_force_const_mem,