From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9AAC23858D1E; Wed, 14 Jun 2023 11:38:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AAC23858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686742725; bh=oUCp7twqNZWHg9fA6wmjCaliT7H/koby8oMBHppFo0A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IglohaCiUXk/RaRaxu34Ck9OoVJjOMDOSn7grAWZb4hPRqC4jCdvcn3WCpuQa0Ia/ 4Ca/R7EmADTLFAodJFpwhDpHgQfhWl4Tn+hWZsl31mu0Uu1QpaFKqq4R/M3bGu8L5A D8EBjnaXKGMy7ZcArLrS/G1h3rnwAktFNNA+sWoQ= From: "david at westcontrol dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110249] __builtin_unreachable helps optimisation at -O1 but not at -O2 Date: Wed, 14 Jun 2023 11:38:45 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: david at westcontrol 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: 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=3D110249 --- Comment #2 from David Brown --- My apologies - it does not optimise the code to a single aligned load at -O1 (at least, not with the combinations I have now tried). The code was originally C++, with a reference, which /does/ exhibit this behaviour of ha= ving better code at -O1 than -O2. I had translated the reference to a pointer to get more generic code that is valid as C and C++, but I don't see the same effect with the pointer. For a reference, the issue is as I first described: #include #include uint64_t read64r(const uint64_t &x) { if ((uint64_t) &x % 8 ) { __builtin_unreachable(); } uint64_t value; memcpy( &value, &x, sizeof(uint64_t) ); return value;=20=20=20=20=20 } I tested with 64-bit RISC-V and 32-bit ARM using trunk (gcc 13.1, I think) = on godbolt.org. The only relevant flag was the optimisation level. =