From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 760E43858D20; Wed, 31 Jan 2024 11:48:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 760E43858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706701709; bh=yUys9gjq95Jade0BCdy7OZej+hSUoDaeAnUStHkwnDU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rnK2mBZlzDt0Gv7whG7fJaTdrNUL9YYCmztWRMRVfJb0R9NUZg1uQtP3YxMFUDerG p/jdpiHA2Bu3ptN8b88fuOgDXQ3NnEEZ6fPnbdd7D/FhLPGVB9EzKQy5P9uno78s/b Oa858G31eH77YJ7nXhzSgbAGb+2jNkNjsGcqBOoA= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113134] gcc does not version loops with early break conditions that don't have side-effects Date: Wed, 31 Jan 2024 11:48:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: juzhe.zhong at rivai dot ai X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113134 --- Comment #19 from JuzheZhong --- The loop is: bb 3 -> bb 4 -> bb 5 | |______=E2=AC=86 |______________=E2=AC=86 The condition in bb 3 is if (i_21 =3D=3D 1001). The condition in bb 4 is if (N_13(D) > i_18). Look into lsplit: This loop doesn't satisfy the check of: if (split_loop (loop) || split_loop_on_cond (loop)) In split_loop_on_cond, it's trying to split the loop that condition is loop invariant. However, no matter bb 3 or bb 4, their conditions are not loop invariant. I wonder whether we should add a new kind of loop splitter like: diff --git a/gcc/tree-ssa-loop-split.cc b/gcc/tree-ssa-loop-split.cc index 04215fe7937..a4081b9b6f5 100644 --- a/gcc/tree-ssa-loop-split.cc +++ b/gcc/tree-ssa-loop-split.cc @@ -1769,7 +1769,8 @@ tree_ssa_split_loops (void) if (optimize_loop_for_size_p (loop)) continue; - if (split_loop (loop) || split_loop_on_cond (loop)) + if (split_loop (loop) || split_loop_on_cond (loop) + || split_loop_for_early_break (loop)) { /* Mark our containing loop as having had some split inner loops.= */ loop_outer (loop)->aux =3D loop;=