From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B11503858CD1; Wed, 31 May 2023 08:51:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B11503858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685523095; bh=3/rA8oamBOH+romAdVglCSvJEj/QMkR+2QSyPFrVB4I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Aq+qVvhc5l2MHEXqupyFH3m/QiMJ+QsmFb3nIda6DQja6nYc05mD9nyb7RlCFSH8y VicCIoHjs6eoLM/TpUz5A2SAYffpzzKlN4aGFUmz17Pq8KMbe7rGy3o+TosT69gRZ7 /lDfgyeeC+dNCjgleYtOmfxbm02OR1n8C0cLzt7I= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/110052] useless local variable not optimized away Date: Wed, 31 May 2023 08:51:35 +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: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: WAITING 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_status cf_reconfirmed_on everconfirmed 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=3D110052 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |WAITING Last reconfirmed| |2023-05-31 Ever confirmed|0 |1 --- Comment #2 from Richard Biener --- /* This is the original code, the local variable is superfluous */ int size =3D foo->size; if (!m) m =3D myrealloc(m, 256, &size); foo->size =3D size; I'm not sure we are allowed to change the &size argument to &foo->size since it's observable whether the argument is equal to &foo->size or not since 'foo' is global and myrealloc could have access to it and also clobber it. Consider myrealloc(..., int *size) { *size =3D 4; foo->size =3D 0; } if 'foo' were global. Can you make the testcase avoid these considerations? I think we have no pass doing this kind of transform. Maybe sth along int size1, size2; foo (&size1); size2 =3D size1; bar (&size2); of course since size1 escapes to foo() bar() might do the same as myrealloc above and it would break passing &size1 to bar().=