From patchwork Mon Aug 9 08:34:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1514961 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+incoming=patchwork.ozlabs.org@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=Rmu128PG; 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 4GjqBj1lXJz9sWX for ; Mon, 9 Aug 2021 18:34:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98AAA388A029 for ; Mon, 9 Aug 2021 08:34:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98AAA388A029 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1628498073; bh=2lAfAhZ4ds1xaoCGQfqC+4N4zNw4d9AZt23COLlAkU4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Rmu128PGGYHq/jlgGkKgyzVawUU1mshYtTfaYn0l2bE5MWx8jL3QiXJM7LZ6BmLLF iGUwSwBRyHNSwTa62Z8wQ28LT5dYqr5Woa+rsa4XZU2MtfL4YGsZmf/zMb64frTRgm gIePQYpC+AyRE0MfIJRrwZ9vG5RLzGKjHLxLPono= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 1B3803858400 for ; Mon, 9 Aug 2021 08:34:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1B3803858400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F1EFC21EDC; Mon, 9 Aug 2021 08:34:09 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D6ED31451A; Mon, 9 Aug 2021 08:34:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id j8NgM4HoEGGjOQAAMHmgww (envelope-from ); Mon, 09 Aug 2021 08:34:09 +0000 Date: Mon, 9 Aug 2021 10:34:09 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/101824 - properly handle volatiles in nested fn lowering Message-ID: <5n952073-937o-q256-no9o-9p624980s182@fhfr.qr> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: jakub@redhat.com, ebotcazou@adacore.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When we build the COMPONENT_REF of a formerly volatile local off the FRAME decl we have to make sure to mark the COMPONENT_REF as TREE_THIS_VOLATILE. While the GIMPLE operand scanner looks at the FIELD_DECL this is not how volatile GENERIC refs work. Bootstrap & regtest in progress on x86_64-unknown-linux-gnu. I'm going to try scrapping the processing of the FIELD_DECL from the operand scanner as followup. Frontends generally seem to process the FIELD_DECLs volatile setting and set the COMPONENT_REF volatile seetting accordingly - so I wonder whether we should change build3 to do that as well for convenience? 2021-08-09 Richard Biener PR middle-end/101824 * tree-nested.c (get_frame_field): Mark the COMPONENT_REF as volatile in case the variable was. * gcc.dg/tree-ssa/pr101824.c: New testcase. --- gcc/testsuite/gcc.dg/tree-ssa/pr101824.c | 19 +++++++++++++++++++ gcc/tree-nested.c | 1 + 2 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr101824.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c new file mode 100644 index 00000000000..d5987e14360 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-pcom-details -fdump-tree-optimized" } */ + +int main() +{ + volatile int y; + void bar() + { + __builtin_printf ("%d", y); + } + while (y) + ; + return 0; +} + +/* Make sure the load from y is correctly interpreted as volatile, even + when going through FRAME. */ +/* { dg-final { scan-tree-dump-not "Executing predictive commoning" "pcom" } } */ +/* { dg-final { scan-tree-dump " ={v} FRAME" "optimized" } } */ diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index 0c3fb029054..cc59526dab8 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -1033,6 +1033,7 @@ get_frame_field (struct nesting_info *info, tree target_context, } x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE); + TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (field); return x; }