From patchwork Tue Oct 17 06:26:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 153928 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3933401vqb; Mon, 16 Oct 2023 23:26:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtSaoANlm6ONPgXKUknnlcKMm/nDczjJqDIp0r8gJSmzWHUt27h3kWyhRNTNWxxDbHw63s X-Received: by 2002:a05:620a:3c94:b0:774:1bb4:502d with SMTP id tp20-20020a05620a3c9400b007741bb4502dmr1105001qkn.74.1697524000909; Mon, 16 Oct 2023 23:26:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697524000; cv=pass; d=google.com; s=arc-20160816; b=qS9MMzsLwpen5FcOFuFcrMObicjCdDb5PaxF8MJdSK6fjuv2uWQfdzUUnTejD9IrP7 KTy5PKjStRSkGh89hh5RhQD3CZmEaBkDkb9v1csLUG5Zlmez9TuM0QBcD7b3Fc5IAYYf CavjzIRDXOuQoQhGtEXO5/WndwFabYWEfVAL1u6O7vOzAZX7AyZQUQCeKCe9heWIJywf 95G/AFlr0PDhDj9erxwrbYhaVQKPtF1nW6XrooLcLdVpuvoW9JIFHKb80bS3oOuSkvAZ V5YpPeXzXAd6+rTz6ryXXUZFbSXJriz9CSQgp7sjmfs/6dC9MzxCH2zepnh9zt4Ic2Fw 5mIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:to:from:date:arc-filter:dmarc-filter :delivered-to; bh=aCSTPheb2h3YFCM841/M/WcrzsCsv+vMF8diiKSKApY=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=WLPXyIBtvwqsnYMcn8693uoEtYSGnsNrGQMEFbMGlxAjKyA9yMfXun+BH+5WGW0Jwd 8wPpfQVnTy7rQEOhh3Hmx99pNMzNwOh6TejKlsl2uwcUcsJxVs5rv0wicOqI1FrD+1ms VTcdAxoK36YcQv++m/xYPw6HU6re3vMbXRgkyV0tOXxU1QSRn+rULFGanFCeLiM6GtoV ePPPmM50w7oYWQkuIOkHpW0moW5SMXVT9U/geSFweW0zNskvPFjHjyCta2B+m5M6853N OW/SaJyETEfw2XhbD641SP3Nv6N1A3wKrZu7bnPJ1N1EOtpte+vaffMP/Iz53VxOZeo1 R+3A== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j13-20020a05620a288d00b0077701e9f740si634019qkp.775.2023.10.16.23.26.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 23:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9AACF3858C3A for ; Tue, 17 Oct 2023 06:26:40 +0000 (GMT) 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 [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id A9FF13858D33 for ; Tue, 17 Oct 2023 06:26:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9FF13858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A9FF13858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697523974; cv=none; b=gIeryLzc41+XXDiYbRXneuSGKL7wBLO57K68u9fh0IXWY1wu9CFDHd2cGfOIM0iIiyugxnomTIj6SWYppwbcfl5fXLfbR6GiGNhn2aPpBDV97NCH06TmGa3NN0p4IEh3+pvNUiOrKFEUIgzvXWcQF2jHOW/T96IvgzxdCd/QSrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697523974; c=relaxed/simple; bh=BmgEcDappIjYjrGIJOSpSW0H9/60Q8V+vVFNN3UjUAw=; h=Date:From:To:Subject:MIME-Version; b=ZM6u4CzF/nEnM0dQe52t4gf/69feidi5PLjjtcJrYwz7WG2FcnW8XHXND7DHTkPKgCDZRzIR2ieFOy6YWQJXk9J9Tst0W0RRY5UUtu0SYpYcaAzyw0ShAmdOvtR8rEGlTZta1o61fwOanlboU9lfsVrTYHWUcqQPqeMrtK2MlNU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 069CB21857 for ; Tue, 17 Oct 2023 06:26:08 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C66E92D316 for ; Tue, 17 Oct 2023 06:26:07 +0000 (UTC) Date: Tue, 17 Oct 2023 06:26:07 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/111818 - failed DECL_NOT_GIMPLE_REG_P setting of volatile User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=none; spf=softfail (smtp-out1.suse.de: 149.44.160.134 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-0.01 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[149.44.160.134:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; R_SPF_SOFTFAIL(0.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; VIOLATED_DIRECT_SPF(3.50)[]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_NA(0.20)[suse.de]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -0.01 X-Rspamd-Queue-Id: 069CB21857 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP 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 Message-Id: <20231017062640.9AACF3858C3A@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779982926726721374 X-GMAIL-MSGID: 1779982926726721374 The following addresses a missed DECL_NOT_GIMPLE_REG_P setting of a volatile declared parameter which causes inlining to substitute a constant parameter into a context where its address is required. The main issue is in update_address_taken which clears DECL_NOT_GIMPLE_REG_P from the parameter but fails to rewrite it because is_gimple_reg returns false for volatiles. The following changes maybe_optimize_var to make the 1:1 correspondence between clearing DECL_NOT_GIMPLE_REG_P of a register typed decl and actually rewriting it to SSA. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/111818 * tree-ssa.cc (maybe_optimize_var): When clearing DECL_NOT_GIMPLE_REG_P always rewrite into SSA. * gcc.dg/torture/pr111818.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr111818.c | 11 +++++++++++ gcc/tree-ssa.cc | 17 +++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr111818.c diff --git a/gcc/testsuite/gcc.dg/torture/pr111818.c b/gcc/testsuite/gcc.dg/torture/pr111818.c new file mode 100644 index 00000000000..a7a91111d71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr111818.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +static void foo(const volatile unsigned int x, void *p) +{ + __builtin_memcpy(p, (void *)&x, sizeof x); +} + +void bar(void *number) +{ + foo(0, number); +} diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc index ebba02b8449..2f3210fcf61 100644 --- a/gcc/tree-ssa.cc +++ b/gcc/tree-ssa.cc @@ -1788,15 +1788,20 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs, maybe_reg = true; DECL_NOT_GIMPLE_REG_P (var) = 0; } - if (maybe_reg && is_gimple_reg (var)) + if (maybe_reg) { - if (dump_file) + if (is_gimple_reg (var)) { - fprintf (dump_file, "Now a gimple register: "); - print_generic_expr (dump_file, var); - fprintf (dump_file, "\n"); + if (dump_file) + { + fprintf (dump_file, "Now a gimple register: "); + print_generic_expr (dump_file, var); + fprintf (dump_file, "\n"); + } + bitmap_set_bit (suitable_for_renaming, DECL_UID (var)); } - bitmap_set_bit (suitable_for_renaming, DECL_UID (var)); + else + DECL_NOT_GIMPLE_REG_P (var) = 1; } } }