From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0714A3858D28; Tue, 16 Jan 2024 13:21:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0714A3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705411312; bh=xkpQtuR0+Zjn7qMjJ/IX8pFtyV3kzQ9MEP5DpJqmoGU=; h=From:To:Subject:Date:From; b=IbmttXMiwDflUkTnmE1nU+3X4VK9sEb+nh0GBcXv7niZL3iBmKI3/1Ly1nV/S1eBu o2SvD8eTN4iKalTjkooKcfdM5bCa6achICjIHzUiw6WH9qcyUQw7PGN1PyxtwRhk1Q EJabRvByvlTNVzWwNSIDc60YkjOPWrvgByvn+6z8= From: "carnet at student dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/113422] New: Missed optimizations in the presence of pointer chains Date: Tue, 16 Jan 2024 13:21:51 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: carnet at student dot ethz.ch 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=3D113422 Bug ID: 113422 Summary: Missed optimizations in the presence of pointer chains Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: carnet at student dot ethz.ch Target Milestone: --- https://godbolt.org/z/hdWKn4bjc All three functions write to the same variable (b). Clang is able to optimi= ze this. GCC -O3 cannot always do this. Assembly for foo is writing to **d instead to directly write 1 to b. There = is similar behavior for bar and baz. Clang optimizes the code to directly writ= e to b. Baz is fully optimized only if the foo and bar are removed. int b =3D 0; static int *c =3D &b; static int **d =3D &c; static int ***e =3D &d; void foo() {***e =3D 1;} void bar() {**d =3D 1;} void baz() {*c =3D 1;} Assembly code: foo: movq d(%rip), %rax movq (%rax), %rax movl $1, (%rax) ret=