From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 884923858C42; Sat, 30 Dec 2023 16:21:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 884923858C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703953302; bh=qVtYZHlzikTqpsqVZtHwlyS+nKwfrHGDoLko0UxOuMc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NYVzRGqyF6YP1i8EJso/jQWpbsAz9yMLkxfWTC/pgj1v1e6ZfksnyAqaEzDec/0uQ lATg/lokiDVFG5jEX5SQAeMzMbW6ytVh3lf4y0v3EqmImiX1gjUXqWyhw1iWjhEuey sqjNV+qxiJugLZ5z891z+MRnf1SoZKG9rjV0+qmo= From: "goon.pri.low at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/112662] missed-optimization: loop increment until wrap Date: Sat, 30 Dec 2023 16:21:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: goon.pri.low at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: pinskia 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=3D112662 --- Comment #2 from gooncreeper --- I believe I got my initial optimized function wrong, it should actually be = this unsigned opt(unsigned a) { if (++a > 999) a =3D 0; return a; } opt: lea eax, [rdi+1] xor edx, edx cmp eax, 1000 cmovnb eax, edx ret Which is a bit more clear also.=