From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 416043858D33; Fri, 2 Feb 2024 03:38:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 416043858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706845136; bh=w/cuvz6Q1P4h2Ong6tllwGnsj2HFWlq3QEF3fHV+LW0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CZS0CCcODz0oUIcsYIO6njBBySue90rALFqam01NMPOpZmV7aynUPug4Xu74dVS5u wV2VXAKlCnnFKDXxg5okuGm/J26vgqFqsAA0X2qqXJMF260OMai3WD+rOuS/2o4q57 +JIPa9wchTHY9A+eY73OqLOq9pfkGmrgxohmNHeE= 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: Fri, 02 Feb 2024 03:38:54 +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 #21 from JuzheZhong --- Hi, Richard. I looked into ivcanon. I found that: /* If the loop has more than one exit, try checking all of them for # of iterations determinable through scev. */ if (!exit) niter =3D find_loop_niter (loop, &exit); In find_loop_niter, we iterate 2 exit edges: 1. bb 5 -> bb 6 with niter =3D (unsigned int) N_13(D). 2. bb 3 -> bb 6 with niter =3D 1001. It just skip niter =3D (unsigned int) N_13(D) in: if (!integer_zerop (desc.may_be_zero)) continue; find_loop_niter (loop, &exit) return 1001 with skipping (unsigned int) N_13(D). Should it return MIN (1001, (unsigned int) N_13(D)). I prefer fix it in ivcanon since I believe it would be more elegant than fi= x it in loop splitter. I am still investigating, any guides will be really appreciated. Thanks.=