From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DAD9D3858C53; Wed, 14 Jun 2023 12:43:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAD9D3858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686746591; bh=hiWCHpEn35JIi7doyz+0mWta/+t0oW0y+nn8EcmLs/0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TEH9fxtQeB9LMCnXrAoakRRVGgfGGZoM2HcSMO+gRru3N1h4kFH6s487Ef3Aueymz o6z6/4Bes+hRykff+QmGv+CyLMeIVmBy0cwEt+kVwxS7P6dRusi2Jz1LKNICtB/0Vl AHjOhjZ3pluWeq7WX+NVERcZZUzaz7gDApqa6+Ro= 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 12:43:11 +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 #4 from David Brown --- Yes, __builtin_assume_aligned is the best way to write things in this particular case (and optimises fine for -O1 and -O2). It is also clearer in the source code (IMHO), as it shows the programmer's intention better. I am just a little concerned that optimisation hints provided by the progra= mmer via __builtin_unreachable are getting lost at -O2. When the compiler knows that something cannot happen - whether by __builtin_unreachable or by other code analysis - it can often use that information to generate more efficient code. If that information can be used for better code at -O1, but is lost = at -O2, then something is wrong in the way that information is collected or pa= ssed on inside the compiler. Any case of -O1 generating more efficient code than -O2 is a sign of a problem or limitation. So I am not particularly bothered about this one piece of code - I am repor= ting the issue because it might be an indication of a wider problem.=