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: 177006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7460721vqy; Mon, 11 Dec 2023 18:03:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcykugEMMYjkkFsO6G+fmo6/gDD/9WfYwxCkl0hvmq4N3hxErLuw3V1Zm5TcxaJ1+nKxuE X-Received: by 2002:a05:620a:1273:b0:77d:ca8b:3002 with SMTP id b19-20020a05620a127300b0077dca8b3002mr6509554qkl.17.1702346610023; Mon, 11 Dec 2023 18:03:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702346610; cv=pass; d=google.com; s=arc-20160816; b=rN9MlkfLJ+NGHzrcwnd0mR1zQ1oYDUPXkZkh4YXXMfOdmjcMIExRqh/Inx8jTnqyy5 Wa/LVl0aPK+uf3ljlTCpfdtF+w2XmsBDrzZQKaqSMMi/N+n+0SMmEFCuHxNbpS0uzYJ+ JKFvACU5E7vR0yqZtqLeS8vqea/QU69fBdQ/t3JjLxMGkVzITu0fnE1n6gQkKED9vYIl 7UMacVDdSsPqrX7/VHX3+wECsu5Col1LN0gRP94RY6ZxpVGcDIMyeM2sgVoG2QpeadG1 4AmdfC1KnfkWVdgqwNXbdBQ3GULcr5Mtp4c3q8+xUR9X+VZSFKFSq0lyPF5O4yymi+2s 2cLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:organization:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=/iPqVMLxRLgznp1Rbg6k/WMCWSv1S900lI6xahSR0eA=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=woDKU08eu9yVI7z64DTl1F+0uDjxtRmIjgFR5CLtrLf5p36QkgLCAl3mC4OLFal+u9 V9RWbWCo4HfNqNdRxn6xlQ6KRBh4FliuTB5Pf4pkgtdXh4iu7UbbkmML66q5nHtdjYom sKC08j7MXzUNJQoBWjtq1u1Gpke2GTvxeIcccZ9rd21jus+9/ML9C0eYJiBFw9VP9YHo saZTmRyFLfemepje4om8m0g7Sy2TawqU18mpP+vsrmBSIHLMbMt8pcNN1PKSNzmRGOnG wpjb+9YxksHO87gtYFIQGEXL8j8Csblfq1gIRGj1k72ioATrtMFL4uYnd2CXyjE3mTNj +qMA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b="FfyaIn/a"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j9-20020a05620a410900b0077d7b1989dasi9899319qko.686.2023.12.11.18.03.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:03:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b="FfyaIn/a"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFB333858032 for ; Tue, 12 Dec 2023 02:03:29 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785039798667723677 X-GMAIL-MSGID: 1785039798667723677 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); +} From patchwork Tue Dec 12 02:48:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 177060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7475791vqy; Mon, 11 Dec 2023 18:48:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE83VedxRCl+t6guoDUyppGKQXKm9cMTvU9At/vRFHWjgn4NkJxa1s9sFAR4WqZxBTTMhbh X-Received: by 2002:a05:620a:4901:b0:77d:a68b:8b7d with SMTP id vy1-20020a05620a490100b0077da68b8b7dmr6549592qkn.1.1702349336726; Mon, 11 Dec 2023 18:48:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702349336; cv=pass; d=google.com; s=arc-20160816; b=MMlnIkXBs+bgnVdUD/HfYHuC8vamf8peiLvWMlxy/PersKBfcvaX4YS8ctOnW/EXDU UzI6IxfhMbzqsQLLVhQMQ5lan5ylUiagdoxe+e71ik7xaFuG2+Z0Fyspc3AqkW9lhe3e yC8xRCbpjA8n8Rbke0a0eIjfwXSm8FT2iTQsvorczMyDhxDYDXbnQ2zVJ9JOuxXIQRjh MbguQ98peuzmmc5jb1PjIdRWZ3qnDTpXn/BGt6K+/4Z8swsqjVw9IMMFWfJrIwwPfPSY 6Aqfu944QOLQb0/34H5XiDvhOM+46YOyt800qyg7wByg4E1m0UeDJcimGycO+3zoudrB 4m8w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:in-reply-to:date:references:organization:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=SxeCrt9CBhuaFXUJq6rJv4RdV5UDc6T8V8S8EG56w/E=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=YG0lS2pdd6QvrF0zpKeeNnzl65QE2BvwC42hJKv4vIcNlPIB4kfCXG/AC17I3yxDYa yA6vS+hT3gIm8cD/bic4y8mDuVM/N+09/60P5jWr/SD1dAWbzNOiU7UrgnGxxC7bCVYY fECaU7+xa4LLYQ75aitI5zAokwv+urKQob5ViGX+oLZ/+iW0llUaxPk2WA6DK3v5ayvg b6hT1NCfU+zJT0ll9eVlfwoDeK9Ubv4hOh3vNRIbroj67ZEDiVl0x1MmeH3ES13YrsX1 GIRSofiuE+5CTOpnXOd6qVlDbUk4mKDmB2vGwRyEv07ZBkhp2Nt+Ryd6Y5pSLCuGP2q0 o5qg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=UfhBlZcQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id w14-20020a05620a444e00b0077d72ae1615si10599504qkp.265.2023.12.11.18.48.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:48:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=UfhBlZcQ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E3C43857BB1 for ; Tue, 12 Dec 2023 02:48:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id E27423858C54 for ; Tue, 12 Dec 2023 02:48:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E27423858C54 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 E27423858C54 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702349313; cv=none; b=rZQX0KOvp7m7+EpS53dQ1fclG2XB6ioj+FAgs0ovaCJsxI7dvEDcX6/9UZBCgLvxOJWYzWP10oqdHpkAlyQPy5gtwgD4ToedJMRkUW2PGDfvCs7LlCXBFGcGN+6qVGcLftsMg3jUYIPexbAX8xQaMOJmXacvVLgpJVXBUg9mzow= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702349313; c=relaxed/simple; bh=bjPkjexsYB9lLmb+vjPlrjMhAZ2cYVJkMgz9JUy5jKA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PLCosY8JaMPVEJOwKlt3YpWKWTiO0el01bJs2YaMDo4DvLB1b8wdcWpMZqZW20Ev5yb8Qk+PzF24cgxygy4bwfACZ8j0EbFrqYzc2NQ2LMaYSI1mnKNLQs0WDLKNiVB5hQ73kXw5r0tr4a+XdruGM0GxWN++hsXEWhGGQDMk3R0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6d9e756cf32so3140695a34.2 for ; Mon, 11 Dec 2023 18:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702349307; x=1702954107; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SxeCrt9CBhuaFXUJq6rJv4RdV5UDc6T8V8S8EG56w/E=; b=UfhBlZcQm2+i2jfOaaBZufhIW4Q2+PIi+ste8G2TV9NF9RgS2d/yn10JBGvDHziIQ8 FxWjaHCpTcTMpuCUbGFiCN8EZgwyj20aVSSsfJBAqvfsMOgWlZlomHPD+ZOpMY9C6Ql2 B4b1gEk8yITkuiD45+NidF7uQbpuraRDq/9NdULJzn/ASI/5LwrBa+0vua5pdzCOwOgR HF0U6viC42085BKMAEljAyw2Ql7D/Nrdgq9uBh+PCJJ61JmLvm+fidbJ2eX0Ub+ZBAwM IebNjU4hqBfiOlYf8vZpr4PumCO9ODAC69qklMdSfRSoD7YIFcC6sQoLtAhLSR9Q46+X liqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702349307; x=1702954107; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:to:from:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=SxeCrt9CBhuaFXUJq6rJv4RdV5UDc6T8V8S8EG56w/E=; b=tB/ENfP8Ddf5sd2JQ/Er/2dOJfFZkjT0y4fr2UQDh54Cba0bN05oqTf5PqPTvHI0iV SBKKVQItgCzbtvr6fYJaU/0+ZtaZkQGrrGYE067e8fTgdRWtjxPXVMeZiQfkTA/LkYlM nXDP77MQuX/MbMN4cwlMgNbUMqyGBgBd4PdbXXkcXyEb6/zC6CB0xKRXoMi44pAt876R obzhWHj7TuGSxdbFGypKRgqSjNMyGUwR/ee/dA+it8qBgiGFQEqjjtyj8LW6IHwjjyaw j9YqJ6b5y2wXsXbRoCp/PaVyDcKUpVsm1SSNiFT9sXztFk+PVlc8xeIPsqLHgOLzASRb JuRQ== X-Gm-Message-State: AOJu0Yx6R2VKeAA04+YEzsGAWtfgQv85sr0wcW0qCdp++bTXe37O/91g PaLCDc0u3Fi60d3igWoZ19tCWY4QVWhZQAWKJsduCQ== X-Received: by 2002:a05:6359:71c1:b0:170:17eb:3790 with SMTP id uf1-20020a05635971c100b0017017eb3790mr5934682rwb.56.1702349306848; Mon, 11 Dec 2023 18:48:26 -0800 (PST) Received: from free.home ([2804:14c:4d1:44a5:f4d9:b7a4:4fb8:376f]) by smtp.gmail.com with ESMTPSA id q4-20020a17090a750400b0028ac07bb4e9sm188612pjk.28.2023.12.11.18.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 18:48:26 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3BC2mGZ8398385 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 11 Dec 2023 23:48:17 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH #2/2] strub: drop volatile from wrapper args [PR112938] Organization: Free thinker, does not speak for AdaCore References: Date: Mon, 11 Dec 2023 23:48:16 -0300 In-Reply-To: (Alexandre Oliva's message of "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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785042658381192122 X-GMAIL-MSGID: 1785042658381192122 On Dec 11, 2023, Alexandre Oliva wrote: > (there's a #2/2 followup coming up that addresses the ??? comment added > herein) Here it is. Also regstrapped on x86_64-linux-gnu, along with the previous patch (that had also been regstrapped by itself). I think this would be a desirable thing to do (maybe also with TYPE_QUAL_ATOMIC), but I'm a little worried about modifying the types of args of the original function decl, the one that is about to become a wrapper. This would be visible at least in debug information. OTOH, keeping the volatile in the wrapper would serve no useful purpose whatsoever, it would likely just make it slower, and such top-level qualifiers really only apply within the function body, which the wrapper isn't. Thoughts? Ok to install? Drop volatile from argument types in internal strub wrappers that are not made indirect. Their volatility is only relevant within the body of the function, and that body is moved to the wrapped function. for gcc/ChangeLog PR middle-end/112938 * ipa-strub.cc (pass_ipa_strub::execute): Drop volatile from internal strub wrapper args. for gcc/testsuite/ChangeLog PR middle-end/112938 * gcc.dg/strub-internal-volatile.c: Check for dropped volatile in wrapper. --- gcc/ipa-strub.cc | 14 +++++++++++--- gcc/testsuite/gcc.dg/strub-internal-volatile.c | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc index 45294b0b46bcb..bab20c386bb01 100644 --- a/gcc/ipa-strub.cc +++ b/gcc/ipa-strub.cc @@ -2922,6 +2922,16 @@ pass_ipa_strub::execute (function *) if (nparmt) adjust_ftype++; } + else if (TREE_THIS_VOLATILE (parm)) + { + /* Drop volatile from wrapper's arguments, they're just + temporaries copied to the wrapped function. ??? Should + we drop TYPE_QUAL_ATOMIC as well? */ + TREE_TYPE (parm) = build_qualified_type (TREE_TYPE (parm), + TYPE_QUALS (TREE_TYPE (parm)) + & ~TYPE_QUAL_VOLATILE); + TREE_THIS_VOLATILE (parm) = 0; + } /* Also adjust the wrapped function type, if needed. */ if (adjust_ftype) @@ -3224,9 +3234,7 @@ pass_ipa_strub::execute (function *) { 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? */ + convert in separate statements. */ if (!is_gimple_val (arg)) { tmp = create_tmp_reg (TYPE_MAIN_VARIANT diff --git a/gcc/testsuite/gcc.dg/strub-internal-volatile.c b/gcc/testsuite/gcc.dg/strub-internal-volatile.c index cdfca67616bc8..0ffa98d799d32 100644 --- a/gcc/testsuite/gcc.dg/strub-internal-volatile.c +++ b/gcc/testsuite/gcc.dg/strub-internal-volatile.c @@ -1,4 +1,5 @@ /* { dg-do compile } */ +/* { dg-options "-fdump-ipa-strub" } */ /* { dg-require-effective-target strub } */ void __attribute__ ((strub("internal"))) @@ -8,3 +9,7 @@ f(volatile short) { void g(void) { f(0); } + +/* We drop volatile from the wrapper, and keep it in the wrapped f, so + the count remains 1. */ +/* { dg-final { scan-ipa-dump-times "volatile" 1 "strub" } } */