From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0A4D63858C39; Tue, 7 Mar 2023 17:07:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A4D63858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678208839; bh=2IQGZFxKxU1GOc7V/WQbqzqLsVdjfT0mumHC+L2sBN4=; h=From:To:Subject:Date:From; b=cq/ftwAfD9lW5QmhVc3EG45eDJ1z8VzLh3u4cC5rbf9RKz34B+8AhxHcYfT15WSGS Vp8NcJFc6zD0U5OoN1G4hjmKLdmcASes9gEUav54kubMI4Bs72NUeoJBU2NQ7xyEUC NM46D4Sz4mwF8tUlfKhOd5YJY/rMa+rRe+6ZVeaM= From: "hbucher at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109057] New: Does GCC interpret assembly when deciding to optimize away a variable? Date: Tue, 07 Mar 2023 17:07:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hbucher at gmail dot com 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=3D109057 Bug ID: 109057 Summary: Does GCC interpret assembly when deciding to optimize away a variable? Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hbucher at gmail dot com Target Milestone: --- I'm trying to figure out why GCC optimizes away a uint8_value that is passed into assembly, basically discarding it. This is in context of Google benchmarks.=20 #include inline void DoNotOptimize( uint8_t value) { asm volatile("" : : "r,m"(value) : "memory"); } static const uint8_t LUT[8] =3D {1,5,3,0,2,7,1,2}; void func1(uint8_t val) { DoNotOptimize(LUT[val]);=20 } In this case Gcc generates func1(unsigned char): movzbl %dil, %edi ret More importantly, the entire static array LUT was optimized away from the object file.=20 https://godbolt.org/z/Tab5T84dM Is this the correct behavior in your understanding?=