From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 558AB3858D39; Mon, 17 Oct 2022 07:17:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 558AB3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665991022; bh=NIGo8v0CMY7e3aGjCLMksR3Svb8qDySiPFFNZkAavGs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mcTKCxYB7lBJQnkeJpnK8gGpBjsexmxrd0ntkWmLu45TYxXYsMywmGTaW1toltFKJ N82ISR7PP+kle3gTNZKBYTWJzVOITIMP2u40wJHPX9qoEWnwx+lGIgtD1OFHUpqzs1 Xy9ma94BRRCpS8gmSlk4EH40iY2OX77wYEmoGyPw= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107285] Incorrect code generation when we use __builtin_constant_p built-in function. Date: Mon, 17 Oct 2022 07:17:01 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: cc bug_status resolution 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=3D107285 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Jakub Jelinek --- That is just bogus expectation. __builtin_constant_p works that it has a cut-off after certain optimizations (for -O0 already very early), if optimizations before it manage to optimize the argument into a constant, it is true. After the cut-off the remaining occurrences are folded into false. So, if bar is inlined or say IPA constant propagated, the argument is const= ant, while if it isn't inlined nor IPA constant propagated (etc.), as seems to be the case for -Og, it is not constant, thus you get what you asked for. __builtin_constant_p better should be used as a way to optimize code without changing the observable behavior...=