From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D16043858D20; Tue, 20 Feb 2024 12:48:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D16043858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708433284; bh=6Dko9WhLVcJI41xQnzmGeTxZ3Ec2dOyB2BbyKmFwctM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=s5ItFxYK7h9kc4FJcbCsyXylYrYQN7DPXigMGmSra+qLQTr4iVtQBdJ0yLi/b2mLd h5psKQHSBM6k5ZQPpzlz5ivGpzug4Far4wk3DCRB2mxNl8TA0Y2SRfugPPlomfScwD zLk5WdMRuiDgRpwTV3tR7D7reL06qgPVQLGIuukk= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109945] Escape analysis hates copy elision: different result with -O1 vs -O2 Date: Tue, 20 Feb 2024 12:48:04 +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: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org 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=3D109945 --- Comment #29 from Jakub Jelinek --- (In reply to Jonathan Wakely from comment #28) > What I tried to say in comment 26 is that we're allowed to always make the > extra copy, which means that global is an invalid pointer, so the program > has UB. >=20 > I think the only flaw in that reasoning is what Richard Smith said in PR > 84414 comment 2: >=20 > "In fact, I think the *only* problem here is that the above rule does not > allow the caller and the callee to observe the objects having the same > address." >=20 > I would argue that it doesn't say they *can't* have the same address (even > if logically it seems obvious that if we copy a temporary to w then at so= me > point there must have been two distinct objects with two distinct address= es). For the passing in registers case, the usual case is that there isn't just a single copy but several, one to the registers, another to other registers or some memory. And I don't see why it couldn't yield the same final memory as the source memory. Usually it will not, in the caller you ask for the stack slot already before the call, but in case the compiler would ask for it only after the call (in alloca-ish way), it could happen to have the same address.=