From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2CFD13858C5E; Wed, 31 May 2023 01:20:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CFD13858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685496010; bh=bvbaet8e2OsXmUmUqc3bvBXSAClNRQ34PNu0o7RsTrU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hodLASCqjr9U+jvrWTkZaVMVzlfZ9T52tDJl8WMU2hkBMez9rZ60JBymHOXmOF+dL 0tujQ75AoLZG+6kdtYoXD41fivTxoFR7xgItQ0uWqa5q2cBgp9vxz+gDXQ1z8m5QgV AV7BOqCz3ctaPof/FbNZ9hyYnE21tpm0nLVuI4QI= From: "ptk.prasertsuk at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110035] Missed optimization for dependent assignment statements Date: Wed, 31 May 2023 01:20:08 +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: 12.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: ptk.prasertsuk at gmail dot com 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=3D110035 --- Comment #4 from Pontakorn Prasertsuk = --- (In reply to Richard Biener from comment #1) > Ick - convoluted C++. We end up with >=20 > void ff (struct MyClass & obj) > { > vector(2) long unsigned int vect_SR.16; > vector(2) long unsigned int vect_SR.15; > vector(2) long unsigned int vect_SR.14; > void * _6; >=20 > [local count: 1073741824]: > vect_SR.14_5 =3D MEM [(struct MyClass > &)obj_2(D)]; > vect_SR.15_28 =3D MEM [(struct MyClass > &)obj_2(D) + 16]; > vect_SR.16_30 =3D MEM [(struct MyClass > &)obj_2(D) + 32]; > _6 =3D operator new (48); > MEM [(struct MyClass2 *)_6] =3D vect_SR.1= 4_5; > MEM [(struct MyClass2 *)_6 + 16B] =3D > vect_SR.15_28; > MEM [(struct MyClass2 *)_6 + 32B] =3D > vect_SR.16_30; > HandleMyClass2 (_6); [tail call] >=20 > and the issue is that 'operator new (48)' can alter what 'obj' points to, > so we cannot move the loads across the call and we get spilling. >=20 > There is no inter-procedural analysis in GCC that would tell us that > 'obj_2(D)' (the MyClass & obj argument of ff) does not point to an > object that did not escape. In fact 'ff' has global visibility > and it might have other callers. >=20 > If you add -fwhole-program then you get the function inlined to main and >=20 > main: > .LFB652: > .cfi_startproc > subq $8, %rsp > .cfi_def_cfa_offset 16 > movl $48, %edi > call _Znwm > movq $0, (%rax) > movq %rax, %rdi > movq $0, 8(%rax) > movq $0, 16(%rax) > movq $0, 24(%rax) > movq $0, 32(%rax) > movq $0, 40(%rax) > call _Z14HandleMyClass2Pv > xorl %eax, %eax > addq $8, %rsp > .cfi_def_cfa_offset 8 > ret >=20 > (not using vectors because 'main' is considered cold). Do you cite an > inline copy of ff() for clang? Hi Richard, The clang snippet I provided is not inlined into 'main' function.=