From patchwork Sat Mar 9 09:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1909941 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=MCSrNdCo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4TsHM11GYfz1yWx for ; Sat, 9 Mar 2024 20:10:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08938385E457 for ; Sat, 9 Mar 2024 09:10:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 7CEEE385DC3A for ; Sat, 9 Mar 2024 09:10:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CEEE385DC3A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 7CEEE385DC3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709975410; cv=none; b=niUrIQvoJ9Jr/EGiEJsWRA/Gf+HX5oijdxrxNXzspvL+/nBf4nx5ma1iEHNe9lws9m9JobbMKVZAnx5ktXcVaY32lMOak3OAD12ClSNarEkMff68V7w1qonoka7hxCN5VH9XC75NHfD8LC0aVASsn212M0DvHt6fxYQBLCKGaG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709975410; c=relaxed/simple; bh=WHchEpWTsf/TUaJWjCQY+0sr2d0hUqBdoAWUuLP0+hY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=u/URE0jNVTe4cXXjJI2LXIDJgEL79+PG+dhe4r3u6E1+rKq8TeOnTbxrPrz5waFs7F+A1uch0tcqL94Vk65mSc0bWqpTZzNXc0ROSRwiugkb8Ucm1+KTgi0Zkn5Q+VIib3U/ObC7ZOm14JemDQirvxeOsmDzQeZ7cq3IDHSyXhE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3c1a1e1e539so2433140b6e.1 for ; Sat, 09 Mar 2024 01:10:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1709975407; x=1710580207; 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=VTmZAXv0xbHLztBmTnQlTKFZ9kV+OvFV+Tb6aVMGL1A=; b=MCSrNdCoYUkdwmVUN29i13KKAXnbpDoJZeT3WED7qlNK2EBkG8OeoIUZLMov+CdMka luIEJmjGljwPz6mps3dzKbSdH8+rWYn3Cf+1zIh/VbCUzuKlkcPfU8pYXTNlyHrEcrWk +7eudgWMyRlIUzTYmkHVxsj7fo0MKbPDUlv8caVabbDcK6Uy+DQ0lYThYtQvDB1V7YYR g9Uvk228AIr8yF4vnuuAKtAn6+3pLHLCsG8Vii9MAlk3yF7eI9nw2IgK5wBd9yN4bQDb 2owmQJxHVDLzGS9YKQKfmZaFdzQLSVuOxXKBuzEPFk+99r8ThJuQKfgnJYDri6E+NagF BEgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709975407; x=1710580207; 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=VTmZAXv0xbHLztBmTnQlTKFZ9kV+OvFV+Tb6aVMGL1A=; b=dO2nfxJmRXw7DgcxI62jUKKhmx83d4MAQNz9xP+FUyQx6CcS80UaqXrTLZbwyxtPD/ U/lP4QNx1OPfxKCux8P4RWmO17CmVTbjiznceEBQHhUC5z3wdJIRezZjGvAG3OGChUqJ veeD0JfIV5xFWVfoqnZZSYi4ozzJsBwv5UzmSSQfaWTqunuaVfPTY8x4Jzv6QYQG9WM8 fgnxkGVf0QUzak5n1J0iG1Kq3Fc7EbFZPekPd/Azlyjsah9x8nUHdhmsKO8zuIp8Utvi 5qOnyG0MNejVWIdG3VY8gUPfNe6/Ad5DacubRSDsuAchfR/v7S5pyduFhNQLbySle6kN rvFg== X-Gm-Message-State: AOJu0YxqrVJ7LCF2JxOHFcMV3p0x9jakjwaR3+K4NhKaGgi24zmp1Ngh UTpc3jCqq6OfTG9drqgkwnG5kW8C9tzNQWjNAR6E+YDJYbrZMrh+f7W/B8Rr2MpbEVmJk8qIY6a kTA== X-Google-Smtp-Source: AGHT+IFtG3ZvV1bxmZ7baCrMxbPxpP6qRRzt1SXRrEFP2D+mgT2noGf2K1tg2g1vScPqiGfZBKHBkg== X-Received: by 2002:a05:6808:bd0:b0:3c2:3518:da82 with SMTP id o16-20020a0568080bd000b003c23518da82mr2026514oik.38.1709975406858; Sat, 09 Mar 2024 01:10:06 -0800 (PST) Received: from free.home ([2804:7f1:218a:c88b:e868:4eaf:8258:c30b]) by smtp.gmail.com with ESMTPSA id du3-20020a056a002b4300b006e5ed7c0b35sm877805pfb.67.2024.03.09.01.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 01:10:06 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 42999tmR693831 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 9 Mar 2024 06:09:55 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH] [strub] improve handling of indirected volatile parms [PR112938] Organization: Free thinker, does not speak for AdaCore Date: Sat, 09 Mar 2024 06:09:55 -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.6 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 The earlier patch for PR112938 arranged for volatile parms to be made indirect in internal strub wrapped bodies. The first problem that remained, more evident, was that the indirected parameter remained volatile, despite the indirection, but it wasn't regimplified, so indirecting it was malformed gimple. Regimplifying turned out not to be needed. The best course of action was to drop the volatility from the by-reference parm, that was being unexpectedly inherited from the original volatile parm. That exposed another problem: the dereferences would then lose their volatile status, so we had to bring volatile back to them. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog PR middle-end/112938 * ipa-strub.cc (pass_ipa_strub::execute): Drop volatility from indirected parm. (maybe_make_indirect): Restore volatility in dereferences. for gcc/testsuite/ChangeLog PR middle-end/112938 * g++.dg/strub-internal-pr112938.cc: New. --- gcc/ipa-strub.cc | 7 +++++++ gcc/testsuite/g++.dg/strub-internal-pr112938.cc | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/g++.dg/strub-internal-pr112938.cc diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc index dff94222351ad..8fa7bdf530023 100644 --- a/gcc/ipa-strub.cc +++ b/gcc/ipa-strub.cc @@ -1940,6 +1940,9 @@ maybe_make_indirect (indirect_parms_t &indirect_parms, tree op, int *rec) TREE_TYPE (TREE_TYPE (op)), op, build_int_cst (TREE_TYPE (op), 0)); + if (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (op))) + && !TREE_THIS_VOLATILE (ret)) + TREE_SIDE_EFFECTS (ret) = TREE_THIS_VOLATILE (ret) = 1; return ret; } } @@ -2894,6 +2897,10 @@ pass_ipa_strub::execute (function *) probably drop the TREE_ADDRESSABLE and keep the TRUE. */ tree ref_type = build_ref_type_for (nparm); + if (TREE_THIS_VOLATILE (nparm) + && TYPE_VOLATILE (TREE_TYPE (nparm)) + && !TYPE_VOLATILE (ref_type)) + TREE_SIDE_EFFECTS (nparm) = TREE_THIS_VOLATILE (nparm) = 0; DECL_ARG_TYPE (nparm) = TREE_TYPE (nparm) = ref_type; relayout_decl (nparm); TREE_ADDRESSABLE (nparm) = 0; diff --git a/gcc/testsuite/g++.dg/strub-internal-pr112938.cc b/gcc/testsuite/g++.dg/strub-internal-pr112938.cc new file mode 100644 index 0000000000000..5a74becc2697e --- /dev/null +++ b/gcc/testsuite/g++.dg/strub-internal-pr112938.cc @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-optimized -O2" } */ +/* { dg-require-effective-target strub } */ + +bool __attribute__ ((__strub__ ("internal"))) +f(bool i, volatile bool j) +{ + return (i ^ j) == j; +} + +/* Check for two dereferences of the indirected volatile j parm. */ +/* { dg-final { scan-tree-dump-times {={v} \*j_[0-9][0-9]*(D)} 2 "optimized" } } */