From patchwork Mon Dec 4 11:53:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 81275 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC7B23857C58 for ; Mon, 4 Dec 2023 11:53:58 +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 [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id EEAA83858C5E for ; Mon, 4 Dec 2023 11:53:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEAA83858C5E 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 EEAA83858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701690824; cv=none; b=qhG/i+kxq+OHgN6qY0LlEbD5QfqVbW5XQ+dNV+POx7OMDwEhEwxHKvDOLXGMAwTPX1ku3eUXwkOlntkc7i7hPj9uyIMV0g7wAfkfRqSZTDWa4uinI/JLb0it6MBGK0o9zmjmG7pUBoZqa2dDxvgCAmOb9OxgG3EIhByR/YS/aW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701690824; c=relaxed/simple; bh=PQg4UJ4xyPPEpGRss+ertDsHyyC47rYKkcrvSGjFEe8=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version: Message-Id; b=XEeHhGk76+qzF9xCfWWTgDUyH4bUWnjmc6Mp7XQoL8mFXYkpDzdb9gLEy4y59iXb5RCx/oDGSUzBGCHXu+q9O9as/jAvhO36tWaxf9vsLK9Ylz0Iqyquy1jmCjYRCFZHFS2PgFKsxKn/yMV8uyNGaVPIeU0Yxg5PktqHu6T7MMo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id E8AF922069 for ; Mon, 4 Dec 2023 11:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701690820; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=onQQdWIJ29DpLYi7VxCbq2FEYOSK9KAJHSOxbqYn0lo=; b=NyldMcOG/Q9e8KeBL7B9yRB8oIhTBRtqWhX4Mevmw5erexYajCyXZCZtpjkQhqzlz0C/0S PI0+62sK8jXj2U5JTcgI5AQM+VPIghb806k8plXi6ZmOg5Ed+Kjh/iikKIdqgyLMrVFZ1B 97Jv5qrlBdYSOg0VgueUERNLZqND9lI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701690820; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=onQQdWIJ29DpLYi7VxCbq2FEYOSK9KAJHSOxbqYn0lo=; b=jfu/jTf6ucMgQM4Tl8cUakeOkWb1QOUfyxymNp2Wxqb+fytUJXQVTFhGPm43o9PYoQb0yp eJRNqmp2wSidEyAg== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id CA9C813588 for ; Mon, 4 Dec 2023 11:53:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 58SGL8S9bWVKWgAAn2gu4w (envelope-from ) for ; Mon, 04 Dec 2023 11:53:40 +0000 Date: Mon, 4 Dec 2023 12:53:40 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112827 - corrupt SCEV cache during SCCP MIME-Version: 1.0 Message-Id: <20231204115340.CA9C813588@imap2.dmz-prg2.suse.org> Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spamd-Result: default: False [-1.89 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(2.21)[0.738]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-scalar-evolution.cc:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -1.89 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, T_SCC_BODY_TEXT_LINE 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+patchwork=sourceware.org@gcc.gnu.org The following avoids corrupting the SCEV cache by my last change to propagate constant final values immediately. The easiest fix is to keep a dead initialization around. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112827 * tree-scalar-evolution.cc (final_value_replacement_loop): Do not release SSA name but keep a dead initialization around. * gcc.dg/torture/pr112827-1.c: New testcase. * gcc.dg/torture/pr112827-2.c: Likewise. --- gcc/testsuite/gcc.dg/torture/pr112827-1.c | 14 ++++++++++++++ gcc/testsuite/gcc.dg/torture/pr112827-2.c | 18 ++++++++++++++++++ gcc/tree-scalar-evolution.cc | 9 +++------ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr112827-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr112827-2.c diff --git a/gcc/testsuite/gcc.dg/torture/pr112827-1.c b/gcc/testsuite/gcc.dg/torture/pr112827-1.c new file mode 100644 index 00000000000..6838cbbe62f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112827-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ + +int a, b, c, d, e; +int main() { + for (; c; c++) { + for (a = 0; a < 2; a++) + ; + for (; b; b++) { + e = d; + d = a; + } + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr112827-2.c b/gcc/testsuite/gcc.dg/torture/pr112827-2.c new file mode 100644 index 00000000000..a7a2a70211b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112827-2.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +short a, b[1], f; +char c, g; +int d, e; +int main() { + for (; f; f++) { + for (d = 0; d < 2; d++) + ; + if (a) + for (g = 0; g < 2; g++) + for (c = 0; c < 2; c += b[d+g]) + ; + for (; e; e++) + ; + } + return 0; +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 065bcd0743d..7556d89e9f8 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3847,13 +3847,10 @@ final_value_replacement_loop (class loop *loop) def = unshare_expr (def); remove_phi_node (&psi, false); - /* Propagate constants immediately. */ + /* Propagate constants immediately, but leave an unused initialization + around to avoid invalidating the SCEV cache. */ if (CONSTANT_CLASS_P (def)) - { - replace_uses_by (rslt, def); - release_ssa_name (rslt); - continue; - } + replace_uses_by (rslt, def); /* Create the replacement statements. */ gimple_seq stmts;