From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 501FC385DC02; Thu, 19 Aug 2021 23:22:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 501FC385DC02 From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96563] Failure to optimize loop with condition to simple arithmetic Date: Thu, 19 Aug 2021 23:22:48 +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: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org 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: cf_reconfirmed_on 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2021 23:22:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96563 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2020-08-11 00:00:00 |2021-8-19 --- Comment #2 from Andrew Pinski --- So I looked into this a little bit, clang is able to do it because it "unro= lls" the loop. The reason why I say that is if you take: int f(int x, int y) { int i =3D 0; while (i <=3D y) { if (i =3D=3D x) return 8; ++i; } return 4; } No compiler is able to optimize this at all. Which should get us: 4 + ((x <=3D y && x >=3D 0)*4). Even changing the original 9 to 1000, clang does not do the optimization ..= .. >although of course it would be nice if it also worked for 99 instead of 9,= where we are not going to unroll. Yes it would but not even clang/LLVM does that :)=