From patchwork Fri Aug 7 11:33:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1342243 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=vrxLNa2L; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4BNNXz4jmLz9sTN for ; Fri, 7 Aug 2020 21:33:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B52BA384B438; Fri, 7 Aug 2020 11:33:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B52BA384B438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596800033; bh=Ftek8bcpTZjxQwCNh+0GSipLwO/ymee4KUw22hqXcks=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vrxLNa2L6bsFiFiJbG0DCOG258gX5yuhDVpUibAzB7HNZ9HwM1NLYWl9j7EzjWSoI ecaBuIWBEoZO+NhXoClUTGrkPnn+cAln/N+QLPjl7501XnoDQ9qce11wimNzqTPIzK K0JF35E82SL/vdmNfJCJEHLJySC8c1gTqRbpC7sA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by sourceware.org (Postfix) with ESMTPS id 01978384BC11 for ; Fri, 7 Aug 2020 11:33:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 01978384BC11 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4BNNXs1lzyzQlCD; Fri, 7 Aug 2020 13:33:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id 1PUNFDMW61hv; Fri, 7 Aug 2020 13:33:45 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] PR target/96347: non-delegitimized UNSPEC UNSPEC_TP (19) found in variable location Date: Fri, 7 Aug 2020 13:33:42 +0200 Message-Id: <20200807113342.2522717-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 1.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2F1F61768 X-Rspamd-UID: 74e2fd X-Spam-Status: No, score=-16.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, On x86, a memory reference reference to a TLS address can be broken out and stored in a register, for instance: movq %fs:8+testYearsBC@tpoff, %rdx Subsequently becomes: pushq %rbp leaq 8+testYearsBC@tpoff, %rbp // later... movq %fs:0(%rbp), %rdx When it comes to representing this in Dwarf, mem_loc_descriptor is left with the following RTL, which ix86_delegitimize_tls_address is unable to handle as the symbol_ref has been swapped out with the temporary. (plus:DI (unspec:DI [ (const_int 0 [0]) ] UNSPEC_TP) (reg/f:DI 6 bp [90])) The UNSPEC_TP expression is checked, ix86_const_not_ok_for_debug_p returns false as it only lets through UNSPEC_GOTOFF, and finally const_ok_for_output is either not smart enough or does not have the information needed to recognize that UNSPEC_TP is a TLS UNSPEC that should be ignored. This results in informational warnings being fired under -fchecking. The entrypoint that triggers this warning to occur is that MEM codes are first lowered with mem_loc_descriptor, with tls_mem_loc_descriptor only being used if that failed. This patch switches that around so that TLS memory expressions first call tls_mem_loc_descriptor, and only use mem_loc_descriptor if that fails (which may result in UNSPEC warnings). Bootstrapped and regression tested on x86_64-linux-gnu, I do also have a sparc64-linux-gnu build at hand, but have not yet got the results to check for a before/after comparison. OK for mainline? Regards Iain --- gcc/ChangeLog: PR target/96347 * dwarf2out.c (is_tls_mem_loc): New. (mem_loc_descriptor): Call tls_mem_loc_descriptor on TLS memory expressions, fallback to mem_loc_descriptor if unsuccessful. (loc_descriptor): Likewise. gcc/testsuite/ChangeLog: PR target/96347 * g++.dg/other/pr96347.C: New test. --- gcc/dwarf2out.c | 30 ++++++++++---- gcc/testsuite/g++.dg/other/pr96347.C | 61 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/pr96347.C diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 9deca031fc2..093ceb23c7a 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -14435,6 +14435,20 @@ is_based_loc (const_rtx rtl) && CONST_INT_P (XEXP (rtl, 1))))); } +/* Return true if this MEM expression is for a TLS variable. */ + +static bool +is_tls_mem_loc (rtx mem) +{ + tree base; + + if (MEM_EXPR (mem) == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem)) + return false; + + base = get_base_address (MEM_EXPR (mem)); + return (base && VAR_P (base) && DECL_THREAD_LOCAL_P (base)); +} + /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0) failed. */ @@ -15671,11 +15685,12 @@ mem_loc_descriptor (rtx rtl, machine_mode mode, return mem_loc_result; } } - mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), - get_address_mode (rtl), mode, - VAR_INIT_STATUS_INITIALIZED); - if (mem_loc_result == NULL) + if (is_tls_mem_loc (rtl)) mem_loc_result = tls_mem_loc_descriptor (rtl); + if (mem_loc_result == NULL) + mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), + get_address_mode (rtl), mode, + VAR_INIT_STATUS_INITIALIZED); if (mem_loc_result != NULL) { if (!is_a (mode, &int_mode) @@ -16631,10 +16646,11 @@ loc_descriptor (rtx rtl, machine_mode mode, break; case MEM: - loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl), - GET_MODE (rtl), initialized); - if (loc_result == NULL) + if (is_tls_mem_loc (rtl)) loc_result = tls_mem_loc_descriptor (rtl); + if (loc_result == NULL) + loc_result = mem_loc_descriptor (XEXP (rtl, 0), get_address_mode (rtl), + GET_MODE (rtl), initialized); if (loc_result == NULL) { rtx new_rtl = avoid_constant_pool_reference (rtl); diff --git a/gcc/testsuite/g++.dg/other/pr96347.C b/gcc/testsuite/g++.dg/other/pr96347.C new file mode 100644 index 00000000000..414d10c73de --- /dev/null +++ b/gcc/testsuite/g++.dg/other/pr96347.C @@ -0,0 +1,61 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-require-effective-target tls } */ +/* { dg-options "-O2 -g -fchecking" } */ + +struct DArray +{ + __SIZE_TYPE__ length; + int *ptr; +}; + +__thread DArray testYearsBC; + +struct FilterResult +{ + DArray input; + bool primed; + + static FilterResult Dthis (FilterResult &pthis, DArray r) + { + pthis.input = r; + return pthis; + } + + int front (void) + { + if (input.length == 0) + __builtin_abort (); + return input.ptr[0]; + } +}; + +FilterResult filter (DArray range) +{ + FilterResult retval; + FilterResult::Dthis (retval, range); + return retval; +} + +DArray chain (DArray rs) +{ + return rs; +} + +struct SysTime +{ + static SysTime Dthis (int); +}; + +int main (void) +{ + while (1) + { + FilterResult val; + __builtin_memset (&val, 0, sizeof (FilterResult)); + val = filter (chain (testYearsBC)); + int year = val.front (); + (void)year; + SysTime::Dthis (0); + } + return 0; +}