From patchwork Tue Feb 4 09:59:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 105963 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 36F883858433 for ; Tue, 4 Feb 2025 10:00:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36F883858433 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ijF6987z; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jc6EI+2w; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ijF6987z; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jc6EI+2w 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:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 8A4E73858D20 for ; Tue, 4 Feb 2025 09:59:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A4E73858D20 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 8A4E73858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738663176; cv=none; b=LJ+F3pvOUZNl5dAtlt+sBxSSxahWDGqt5XfjpiuNQfmMWJPlEikgQJY8eSth4Ck8cPoeZ/TZigvDiRKt5bujLr5qB0X96owcTU9XSmB8VdV0rVdXdh7L25hUpIWgdcsEBAwZ/b01f7Y86C75eIatNfDL6lwrA4nrc9deHZTy9Tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1738663176; c=relaxed/simple; bh=byOHZdc8isKuYb9W2YXIIkCEQJFJdpt6U886g/sSE1k=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=izIVlqEt4EYVd3T4+IWkVcNz2gWTXqi/UPmDaa1+McyWkZfrNdDIgJqNbbur7krLvYdb+KjBOD+7nmW6PdK67HHLUwgxt0yZ4Rc1/DiTLWgrLaS/D7NGTpl3R7UKCZxdlFOO7BGLSvs4Sa7Or3GwmVrwbZqc+8ctxlDv0874RrQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A4E73858D20 Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 7D85721101 for ; Tue, 4 Feb 2025 09:59:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738663175; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=mUJ3a9SrKcIVGsu/x3l+WPEExho/OUFDPqR/E3yscNY=; b=ijF6987zLdPlAXujf/9jsp5BGcVK/tNSffrxerraQtixkbyHmAZsSx2kQVwOjRO69oCFoD p1FNgqbXzes4H1i4gnEansxUYFCWmsJpI6QIolx0/BnqLMgRTHn+QD0uTDvbiIv5UNNrHs S2g+boWebTi64qpXRbSEwNMA8srcmXI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738663175; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=mUJ3a9SrKcIVGsu/x3l+WPEExho/OUFDPqR/E3yscNY=; b=jc6EI+2wQVCC60Kht10x6YDmzOzgNAQmYMkjGDCNytGf+/Zv+LxOTtLRght+4NG146Ityo HhlKuYp2IsSbPVCA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1738663175; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=mUJ3a9SrKcIVGsu/x3l+WPEExho/OUFDPqR/E3yscNY=; b=ijF6987zLdPlAXujf/9jsp5BGcVK/tNSffrxerraQtixkbyHmAZsSx2kQVwOjRO69oCFoD p1FNgqbXzes4H1i4gnEansxUYFCWmsJpI6QIolx0/BnqLMgRTHn+QD0uTDvbiIv5UNNrHs S2g+boWebTi64qpXRbSEwNMA8srcmXI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1738663175; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=mUJ3a9SrKcIVGsu/x3l+WPEExho/OUFDPqR/E3yscNY=; b=jc6EI+2wQVCC60Kht10x6YDmzOzgNAQmYMkjGDCNytGf+/Zv+LxOTtLRght+4NG146Ityo HhlKuYp2IsSbPVCA== Date: Tue, 4 Feb 2025 10:59:35 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/117113 - ICE with unroll-and-jam MIME-Version: 1.0 X-Spam-Score: -1.11 X-Spamd-Result: default: False [-1.11 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.31)[-0.315]; NEURAL_HAM_SHORT(-0.20)[-0.992]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[] X-Spam-Level: X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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~patchwork=sourceware.org@gcc.gnu.org Message-Id: <20250204100025.36F883858433@sourceware.org> When there's an inner loop without virtual header PHI but the outer loop has one the fusion process cannot handle the need to create an inner loop virtual header PHI. Punt in this case. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/117113 * gimple-loop-jam.cc (unroll_jam_possible_p): Detect when we cannot handle virtual SSA update. * gcc.dg/torture/pr117113.c: New testcase. --- gcc/gimple-loop-jam.cc | 12 +++++++++++- gcc/testsuite/gcc.dg/torture/pr117113.c | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr117113.c diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc index 9a2eba02dd9..5e6c04a7d7f 100644 --- a/gcc/gimple-loop-jam.cc +++ b/gcc/gimple-loop-jam.cc @@ -279,13 +279,17 @@ unroll_jam_possible_p (class loop *outer, class loop *loop) body would be the after-iter value of the first body) if it's over an associative and commutative operation. We wouldn't be able to handle unknown cycles. */ + bool inner_vdef = false; for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi)) { affine_iv iv; tree op = gimple_phi_result (psi.phi ()); if (virtual_operand_p (op)) - continue; + { + inner_vdef = true; + continue; + } if (!simple_iv (loop, loop, op, &iv, true)) return false; /* The inductions must be regular, loop invariant step and initial @@ -301,6 +305,12 @@ unroll_jam_possible_p (class loop *outer, class loop *loop) copy, _not_ the next value of the second body. */ } + /* When there's no inner loop virtual PHI IV we cannot handle the update + required to the inner loop if that doesn't already have one. See + PR117113. */ + if (!inner_vdef && get_virtual_phi (outer->header)) + return false; + return true; } diff --git a/gcc/testsuite/gcc.dg/torture/pr117113.c b/gcc/testsuite/gcc.dg/torture/pr117113.c new file mode 100644 index 00000000000..e90ad034a4d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr117113.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-dce -fno-inline" } */ + +int a, b, c; +volatile int d[1]; +void e() {} +void f(int g) {} +int main() { + int i; + for (; b; b--) { + for (i = 0; i < 3; i++) { + e(); + f(d[0]); + d[0]; + } + if (a) + c++; + } + return 0; +}