From patchwork Tue Dec 12 02:02:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1874840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=FfyaIn/a; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sq22d1rGNz20Gd for ; Tue, 12 Dec 2023 13:03:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DA843858418 for ; Tue, 12 Dec 2023 02:03:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 07C843858C5F for ; Tue, 12 Dec 2023 02:03:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07C843858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 07C843858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702346587; cv=none; b=GplnIsWxxB9OEBU/O5XG1rcUAIvZQftR/Eo4MZaMCtsbyeaLDqnajYirr4OjrGf93RvGK2xOcwMQeUsa9gsvtedY23AtNK7uLfZqoAbKgUUd993tKUJE8FfKP17AHJHs5Oai4fz7PEDa0IRZNMcW4I7DPUJduxnIQzjt/jnXpKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702346587; c=relaxed/simple; bh=IjPr4/r+rFFJfee9ggnB5mkdhvMzC2WAzs0gbjfuDCI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=P2wJjfcz5ZAXNrqd6Ih26d/ZkRIufTGEGWYoer2WYKUzTRVm6u8jpgyrmlHsTv/ql27wJO03Chm+3bY+7uI8QyjCEg6uSsufoFOaqcu7XRkKACbh63QumTIendLzJZygJgaLWpugnnoMQJt3aE8W2fZPi+cCFB/hPU53EI4H4qA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3b9f111c114so2067726b6e.1 for ; Mon, 11 Dec 2023 18:03:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702346584; x=1702951384; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=/iPqVMLxRLgznp1Rbg6k/WMCWSv1S900lI6xahSR0eA=; b=FfyaIn/aLTwxUThM/Ok12hZQA0XvIhrXtkkLye72ohNEg8YxeXE1ZSfksFHHqXWUyf fr+bpSNb/mSsz2e7/fO4tVq/dQ49x8U8Nx4CoqVUyCLe+6QZ+Jfsmitzb5dXYBuSwfRh RKxOnT2adkLs2QA3N1+T6zmiuXqriVBUFQLb/d2cXtnuEV6F3zqZwLFvmkNZUVsdEpiy Nph+SaE/x9HyluciOkC4ica2e1t5LEVrVLPsrcfzJHrbXF3vl7gtXvGpquHUuxkTGnUF lepxU528W2mmELyJhVJoU6aHkJQiIyok4Qg5eFylzX0yrfAPEQ6NYYRtwoTtWM348MEo RvbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702346584; x=1702951384; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/iPqVMLxRLgznp1Rbg6k/WMCWSv1S900lI6xahSR0eA=; b=Cqy2/jKI91lwJ+/83O4mJCAb9LbCbH+AmUgQlcNp2Ffh0uUaHQq9JcvH+hDa/tcekN c161EJybQLiBpsNFMKaWfEPtq+WwJiGDYmvyaPeESjemsTF0NAk9CkYAT3ovw5H4jxH4 GGi+A9fTzhKigyis0wmoKeSaNCcOz0dH6tfl405Q/pTCwlKBywlBfXWNE2FeY3zb2xPH LhPUsK94hmAv99FcO935ZJcLC82NXReE7XeTuSVO5CQQQ0FxEtmVAQqSImDdAVoSa8bO XTle89IT1BZIk2XVY08qOHci5kHPFIeU29F9501oTZ9gmH5Q1jDr+QG5oMBUAJujxi62 4+aw== X-Gm-Message-State: AOJu0YwYIuKkdUl9Vq+GMRHJaQlS23SfpiX/CUHGksCw/Vm/dzkYcemO UNbs0XPeXDNmlKU33vAwLDw9XtPtdX11dEb9wxwhrw== X-Google-Smtp-Source: AGHT+IEl9Pdi9e4//ke1Nxcfb8N6/Ea9ZY4zY/+8omzjuqAeSUmuMLFQYnl7QwA/Q2lm7NkZC9Eaqw== X-Received: by 2002:a05:6808:21a9:b0:3b9:e118:e423 with SMTP id be41-20020a05680821a900b003b9e118e423mr5937515oib.32.1702346583749; Mon, 11 Dec 2023 18:03:03 -0800 (PST) Received: from free.home ([2804:14c:4d1:44a5:f4d9:b7a4:4fb8:376f]) by smtp.gmail.com with ESMTPSA id je11-20020a170903264b00b001cffe1e7374sm7381166plb.214.2023.12.11.18.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:03:03 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3BC22o2m397404 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 11 Dec 2023 23:02:51 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH #1/2] strub: handle volatile promoted args in internal strub [PR112938] Organization: Free thinker, does not speak for AdaCore Date: Mon, 11 Dec 2023 23:02:50 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org When generating code for an internal strub wrapper, don't clear the DECL_NOT_GIMPLE_REG_P flag of volatile args, and gimplify them both before and after any conversion. While at that, move variable TMP into narrower scopes so that it's more trivial to track where ARG lives. Regstrapped on x86_64-linux-gnu. Ok to install? (there's a #2/2 followup coming up that addresses the ??? comment added herein) for gcc/ChangeLog PR middle-end/112938 * ipa-strub.cc (pass_ipa_strub::execute): Handle promoted volatile args in internal strub. Simplify. for gcc/testsuite/ChangeLog PR middle-end/112938 * gcc.dg/strub-internal-volatile.c: New. --- gcc/ipa-strub.cc | 29 +++++++++++++++++------- gcc/testsuite/gcc.dg/strub-internal-volatile.c | 10 ++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/strub-internal-volatile.c diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc index 8ec6824e8a802..45294b0b46bcb 100644 --- a/gcc/ipa-strub.cc +++ b/gcc/ipa-strub.cc @@ -3203,7 +3203,6 @@ pass_ipa_strub::execute (function *) i++, arg = DECL_CHAIN (arg), nparm = DECL_CHAIN (nparm)) { tree save_arg = arg; - tree tmp = arg; /* Arrange to pass indirectly the parms, if we decided to do so, and revert its type in the wrapper. */ @@ -3211,10 +3210,9 @@ pass_ipa_strub::execute (function *) { tree ref_type = TREE_TYPE (nparm); TREE_ADDRESSABLE (arg) = true; - tree addr = build1 (ADDR_EXPR, ref_type, arg); - tmp = arg = addr; + arg = build1 (ADDR_EXPR, ref_type, arg); } - else + else if (!TREE_THIS_VOLATILE (arg)) DECL_NOT_GIMPLE_REG_P (arg) = 0; /* Convert the argument back to the type used by the calling @@ -3223,16 +3221,31 @@ pass_ipa_strub::execute (function *) double to be passed on unchanged to the wrapped function. */ if (TREE_TYPE (nparm) != DECL_ARG_TYPE (nparm)) - arg = fold_convert (DECL_ARG_TYPE (nparm), arg); + { + tree tmp = arg; + /* If ARG is e.g. volatile, we must copy and + convert in separate statements. ??? Should + we drop volatile from the wrapper + instead? */ + if (!is_gimple_val (arg)) + { + tmp = create_tmp_reg (TYPE_MAIN_VARIANT + (TREE_TYPE (arg)), "arg"); + gimple *stmt = gimple_build_assign (tmp, arg); + gsi_insert_after (&bsi, stmt, GSI_NEW_STMT); + } + arg = fold_convert (DECL_ARG_TYPE (nparm), tmp); + } if (!is_gimple_val (arg)) { - tmp = create_tmp_reg (TYPE_MAIN_VARIANT - (TREE_TYPE (arg)), "arg"); + tree tmp = create_tmp_reg (TYPE_MAIN_VARIANT + (TREE_TYPE (arg)), "arg"); gimple *stmt = gimple_build_assign (tmp, arg); gsi_insert_after (&bsi, stmt, GSI_NEW_STMT); + arg = tmp; } - vargs.quick_push (tmp); + vargs.quick_push (arg); arg = save_arg; } /* These strub arguments are adjusted later. */ diff --git a/gcc/testsuite/gcc.dg/strub-internal-volatile.c b/gcc/testsuite/gcc.dg/strub-internal-volatile.c new file mode 100644 index 0000000000000..cdfca67616bc8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/strub-internal-volatile.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target strub } */ + +void __attribute__ ((strub("internal"))) +f(volatile short) { +} + +void g(void) { + f(0); +}