From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D62C73858CDB; Thu, 13 Jul 2023 21:00:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D62C73858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689282031; bh=EYVC6mxYJ3NssQTM+8XeRkk8qpAboqhturcdkegURiE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VR2jOr1FSQ6ueJ8BvbQJVehZnQ/MoIioKuM4n6kjoOT6GYhp1GHKTXOO5Z5NAPOLg E5P4bscNQvvTyqaRUh7Jjs+BuYINJMWP1y4u+HSloxFILjVaKyv7L2Kf2KOB1V9XP5 oFH0zEBGtAz/+2cHx0yB8j+DXOhSbNhTLVqGG+qQ= From: "jason at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109112] [[assume(...)]] is not taken into account for structs Date: Thu, 13 Jul 2023 21:00:31 +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.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jason at gcc dot gnu.org X-Bugzilla-Status: NEW 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=3D109112 --- Comment #7 from Jason Merrill --- In an email thread Jakub wrote: ---- Only the simplest assumptions in [[assume(cond)]] where there clearly aren't any side-effects no risks of them are lowered to if (!cond) __builtin_unreachab= le (); in the IL, anything else goes into the condition being outlined in a separate artificial function and an internal function recording the assumption in the IL. The optimizers then can optimize both the artificial function and the caller. The missed optimization thing is that currently only the value range propagation is able to take advantage of the assumptions, and VRP is only able to deal with scalars. We have interprocedural optimizations like IPA scalar replacement of aggregates etc., where we can optimize passing aggregates at function boundaries to passing just some scalars from them if the rest isn't needed etc., but because the assumptions aren't normal calls they'd need tweaks to be able to optimize the assumptions too so that VRP could take advantage of those. ---- Why don't the existing optimizations work on the artificial function the sa= me as any other function? i.e. like struct S { bool x; }; void do_something(); inline void assumption_1 (const S& s) noexcept { if (s.x) __builtin_unreachable (); } void fn(S s) { assumption_1 (s); if (s.x) do_something(); } which is also optimized as expected.=