From patchwork Wed Apr 8 11:49:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 132806 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id A794F4BA2E0D for ; Wed, 8 Apr 2026 11:50:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A794F4BA2E0D 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=zZ5QD0dz; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DUcxqV0u; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=zZ5QD0dz; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DUcxqV0u 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 627B14BA2E09 for ; Wed, 8 Apr 2026 11:49:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 627B14BA2E09 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 627B14BA2E09 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=1775648966; cv=none; b=vZyuH2k/3YDPpof9DqCclVwgOfpkmInXRVIN2TUIfPOC1Y6URpNtcxXxzkUx3+vHEXKoAfzUZDc0cPfh0Dqf00qjitd1ivQxgZ0C2eTM77+v0XzKZu+zwbH4i5OHYHpNwiFf8Srw5/5Vb99n8DvvW6VpnpBPEn2JfWO7sfnUM44= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775648966; c=relaxed/simple; bh=DNBVG/xGl+qlB1CDnrcD1aPZsJipgIb+8ZT8Vb/lez4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=bwHrQTRU27QAbANUwylZzwdFSP6LYIOeEPutXJd93hcvunlYbKtdFnWqe8JMaMyi9WHb1gQ0+doumFdWauyW7VtgSYBsx0f9Z7Ps3lND9oYAr7XA3GDGK/BTQxtW5EedBHmsCzp7jyOQrSVIQNxAHJEGegyfJyDfKMVrwTOuN44= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 627B14BA2E09 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (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 394ED4DA1F for ; Wed, 8 Apr 2026 11:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775648965; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ZfcglJE0j8HrbqpYo/MlMz1tU0RyFbuxlm27k+61JK0=; b=zZ5QD0dzmtGWvaXtsPfW1oWF9JRo8tOmz73tdeJLkXSp/TxM4rQ7oRkvfPGgMh4uXugG9b KE3p8P2723ZuNf1jY9paqxYXx5Kw1xFYBPgYjt9/Xnunygxz/rJEc/shVI74cep6tNoMPN x2calgp23aJiycmrsCEWVIH+Hg0YL2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775648965; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ZfcglJE0j8HrbqpYo/MlMz1tU0RyFbuxlm27k+61JK0=; b=DUcxqV0u7CoNc+PdgwaiGTnjU2bMBObtXyWzQk0mxzhVSEaNlUWv0BIeeuJDFbK7qheaPN 6O7L0pT+5ouwrFCw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=zZ5QD0dz; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=DUcxqV0u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775648965; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ZfcglJE0j8HrbqpYo/MlMz1tU0RyFbuxlm27k+61JK0=; b=zZ5QD0dzmtGWvaXtsPfW1oWF9JRo8tOmz73tdeJLkXSp/TxM4rQ7oRkvfPGgMh4uXugG9b KE3p8P2723ZuNf1jY9paqxYXx5Kw1xFYBPgYjt9/Xnunygxz/rJEc/shVI74cep6tNoMPN x2calgp23aJiycmrsCEWVIH+Hg0YL2o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775648965; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ZfcglJE0j8HrbqpYo/MlMz1tU0RyFbuxlm27k+61JK0=; b=DUcxqV0u7CoNc+PdgwaiGTnjU2bMBObtXyWzQk0mxzhVSEaNlUWv0BIeeuJDFbK7qheaPN 6O7L0pT+5ouwrFCw== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 21A734A0B3 for ; Wed, 8 Apr 2026 11:49:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ExPBBsVA1mmwQAAAD6G6ig (envelope-from ) for ; Wed, 08 Apr 2026 11:49:25 +0000 Date: Wed, 8 Apr 2026 13:49:09 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/124810 - ICE with loop fixup MIME-Version: 1.0 Message-Id: <20260408114925.21A734A0B3@imap1.dmz-prg2.suse.org> X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; MISSING_XM_UA(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from] X-Rspamd-Queue-Id: 394ED4DA1F X-Spam-Score: -4.51 X-Spam-Level: X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, 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 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 fixes fix_loop_placements to properly consider re-parenting only outer loops of a nest. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/124810 * cfgloopmanip.cc (fix_loop_placements): Do not stop iterating when an inner loop didn't get re-parented. Compute the outermost loop we have to consider re-parenting. * gcc.dg/torture/pr124810.c: New testcase. --- gcc/cfgloopmanip.cc | 37 +++++++++++++++++-------- gcc/testsuite/gcc.dg/torture/pr124810.c | 23 +++++++++++++++ 2 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr124810.c diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc index d8acbad6e55..72f7c1896ba 100644 --- a/gcc/cfgloopmanip.cc +++ b/gcc/cfgloopmanip.cc @@ -1061,23 +1061,36 @@ static void fix_loop_placements (class loop *loop, bool *irred_invalidated, bitmap loop_closed_ssa_invalidated) { - class loop *outer; + if (!loop_outer (loop)) + return; + + auto_vec exits = get_loop_exit_edges (loop); + unsigned i; + edge e; + /* We might need to only re-parent an outer loop, but as the constraint + is that we removed an exit from LOOP, we have a limit for what level + of outer loop we eventually have to re-parent to. */ + class loop *outermost = loop; + FOR_EACH_VEC_ELT (exits, i, e) + outermost = find_common_loop (outermost, e->dest->loop_father); + + class loop *outer; while (loop_outer (loop)) { outer = loop_outer (loop); - if (!fix_loop_placement (loop, irred_invalidated, - loop_closed_ssa_invalidated)) - break; - - /* Changing the placement of a loop in the loop tree may alter the - validity of condition 2) of the description of fix_bb_placement - for its preheader, because the successor is the header and belongs - to the loop. So call fix_bb_placements to fix up the placement - of the preheader and (possibly) of its predecessors. */ - fix_bb_placements (loop_preheader_edge (loop)->src, - irred_invalidated, loop_closed_ssa_invalidated); + if (fix_loop_placement (loop, irred_invalidated, + loop_closed_ssa_invalidated)) + /* Changing the placement of a loop in the loop tree may alter the + validity of condition 2) of the description of fix_bb_placement + for its preheader, because the successor is the header and belongs + to the loop. So call fix_bb_placements to fix up the placement + of the preheader and (possibly) of its predecessors. */ + fix_bb_placements (loop_preheader_edge (loop)->src, + irred_invalidated, loop_closed_ssa_invalidated); loop = outer; + if (outer == outermost) + break; } } diff --git a/gcc/testsuite/gcc.dg/torture/pr124810.c b/gcc/testsuite/gcc.dg/torture/pr124810.c new file mode 100644 index 00000000000..bd2b03592d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr124810.c @@ -0,0 +1,23 @@ +/* { dg-additional-options "-fno-tree-ch -fno-tree-dce -fno-tree-dominator-opts -fno-tree-vrp -fno-tree-dse" } */ + +int a, b[9], c, d; +static void e() { + int f[9]; + unsigned char g; +h: +i: + if (a) + goto h; + g = 0; + for (; g < 9; g++) { + b[g] = f[8] ? 0 : g; + if (g) + goto i; + d ? c && d < 0 : c; + } +} +int main() { + while (c) + e(); + return 0; +}