From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 928803858D33; Fri, 5 May 2023 10:10:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 928803858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683281441; bh=OdHeLOkKlovCk7xZ+om/zLwsZcEhmVOUTfRQfRYoQKI=; h=From:To:Subject:Date:From; b=P6bz6v6xewjvCmd2mj9/gLSX4s/DyZ5zDLH7XyBgfoC6z3yD3MO24tW6OfMirWaSX kg6LPKzg7pqMRAdzsAZLCcTIfIrJZ5te7thcI+BHrrbY6bxynpXXLep2vSo1sl12jb X4v9DVy3DuGc9oxHQCliVtbOtThH4MMjsC8Xv1BM= From: "magnus.hegdahl at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109746] New: Fails removing redundant comparison in for loop over multiple variables, unless members of struct Date: Fri, 05 May 2023 10:10:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: magnus.hegdahl at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D109746 Bug ID: 109746 Summary: Fails removing redundant comparison in for loop over multiple variables, unless members of struct Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: magnus.hegdahl at gmail dot com Target Milestone: --- Compiled with g++ (GCC) 13.1.1 20230429 on x86-64 Linux, with -O2 or higher. In the code below, the comparisons with i are redundant because j is increa= sing much faster. GCC manages to optimize this away when i and j are members of some struct, = but not when they are just integers. struct S { unsigned x; }; unsigned f() { unsigned N =3D 1e9, x =3D 0; for (unsigned i =3D 3, j =3D 1; i < N && j < N; i +=3D 2, j +=3D 3) x ^=3D i * j; return x; } unsigned g() { unsigned N =3D 1e9, x =3D 0; for (S i {3}, j {1}; i.x < N && j.x < N; i.x +=3D 2, j.x +=3D 3) x ^=3D i.x * j.x; return x; } int main() { return f(); }=