From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 514583898391; Wed, 7 Dec 2022 15:31:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 514583898391 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670427114; bh=Jiz3ZT7H4wUFn72NHISRhFf+xdK/+nhzvYyPrI88HZ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=svf6DHxRX1uO9gp206Mipzz4ATJJAr5cDS/oBwX0QL/cqlCyx2UHs68LB4CU5jmfy KKex1PESF+22MZAUj6NWx+aSD3RCvP+TUEa7vICZbU6K0XABORCibKFAjEJbm7UzQs ER0w3tAgyJlIgl9IPVH4qH6oeKRQWHFAt0MzNZ8Q= From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107972] backward propagation of finite property not performed Date: Wed, 07 Dec 2022 15:31:52 +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: normal X-Bugzilla-Who: amacleod at redhat 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=3D107972 --- Comment #4 from Andrew Macleod --- Its because we don't go back and re-propagate into previous basic block. T= ake an integral vexample: unsigned=20 foo (unsigned a, unsigned b) { unsigned res =3D a + b; if (res > 100) return 42 if (a > 30 || b > 30) __builtin_unreachable (); if (res > 100) return 42 return res; The branch which restricts the range of a and b to [0,30] causes GORI to recompute "res =3D a + b" on each edge, so those values are pushed along any outgoing edges, and when we see res > 100 the second time we fold that away. Thats all handled buy GORI which is basic-block oriented only. At no point (yet anyway) do we attempt to push these values back further in the CFG, so therefore we don't touch the conditions that were encountered earlier, and cannot eliminate the earlier compare and return.=20=20 I have contemplated a new kind of VRP analysis pass which leverages what we= did with 'assume', propagates known values backwards and looks for opportunities earlier in the CFG that are exposed by information determined later in the = IL.=20 This sort of thing would probably require such a pass.=