From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 390E03858C1F; Tue, 21 Feb 2023 13:38:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 390E03858C1F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676986737; bh=zCji8KJwzhmSI+BZJlMlCwBzgLV+o9nRGrtwxS61nK8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E9Xui85caAh18L2OmgfYNZOxxcptU9GqWzJapSmQw0xKB5SqqiX64OFwN7482kV9s xVehIngihOyeXQNOHnnw9xVTSxgtmnb8ywXFUtR96bG7pTu7GNc9NEh6jP0HOeVeSq F/DV453bEK9tWJutHe6MpJFaIyog674hTbFXhgOk= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108243] [10/11/12/13 Regression] Missed optimization for static const std::string_view(const char*) Date: Tue, 21 Feb 2023 13:38:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: missed-optimization, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: ppalka at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: priority 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=3D108243 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P2 --- Comment #10 from Richard Biener --- I'm not sure if this is supposed to be fixed yet. For the comment#2 testca= se I now get [local count: 1073741824]: _1 =3D __atomic_load_1 (&_ZGVZ4mainE3foo, 2); if (_1 =3D=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 956811341]: goto ; [100.00%] [local count: 354334800]: _2 =3D __cxa_guard_acquire (&_ZGVZ4mainE3foo); if (_2 !=3D 0) goto ; [33.00%] else goto ; [67.00%] [local count: 116930483]: MEM[(struct string_view *)&foo] =3D{v} {CLOBBER}; MEM[(struct string_view *)&foo].str =3D "bar"; MEM[(struct string_view *)&foo].len =3D 3; __cxa_guard_release (&_ZGVZ4mainE3foo); [local count: 1073741824]: _9 =3D foo.len; _8 =3D (int) _9; return _8; so we fail to CSE foo.len because __cxa_guard_release possibly clobbers it (it's global memory). Note the clobbering is necessary to prevent code motion across the lock primitives. Note that __cxa_guard_release also prevents removing the .str initialization since only the .len member is ever inspected. As noted static initializati= on would improve this quite a bit.=