From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 87177385841B; Tue, 31 Oct 2023 08:29:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 87177385841B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698740953; bh=xAWXSCXt6CsJF/84gZkkjhnF9ccmxFrqKfKWxxswo60=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rz0sHrpdwX3UiSCywv/kvV6r7ZZ+NGVmoDb6XORU5FX9HCv6pQ4CQQHIyQJc/F4jz XE/gIuqSUESnWSbLImdJq0N0oeqvo5zh40ha1jCZvQht/x7hQGZkApVuXxzVFV8ILE nYmOoXqgxXyX4KRYyRZoUgCI5M3C3m1YwmEGUilQ= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112296] __builtin_constant_p doesn't propagate through member functions Date: Tue, 31 Oct 2023 08:29:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: everconfirmed bug_status cf_reconfirmed_on assigned_to 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=3D112296 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2023-10-31 Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot = gnu.org --- Comment #4 from Richard Biener --- The issue is that we're inlining "optimized" bodies but somehow "optimize" direct() already in the frontend to ;; Function int direct(Span) (null) ;; enabled by -tree-original < =3D 0>>; that's because we have builtins.cc:fold_builtin_constant_p /* If this expression has side effects, show we don't know it to be a constant. Likewise if it's a pointer or aggregate type since in those case we only want literals, since those are only optimized when generating RTL, not later. And finally, if we are compiling an initializer, not code, we need to return a definite result now; there's not going to be any more optimization done. */ if (TREE_SIDE_EFFECTS (arg) || AGGREGATE_TYPE_P (TREE_TYPE (arg)) || POINTER_TYPE_P (TREE_TYPE (arg)) || cfun =3D=3D 0 || folding_initializer || force_folding_builtin_constant_p) return integer_zero_node; and the CALL_EXPR we have as argument has side-effects. That all looks like from prehistoric times, but I'm only going to remove the TREE_SIDE_EFFECTS check which makes the direct and indirect cases produce the same result.=