From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AE4993857416; Tue, 5 Oct 2021 06:19:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE4993857416 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102540] [12 Regression] Dead Code Elimination Regression at -O3 since r12-476-gd846f225c25c5885 Date: Tue, 05 Oct 2021 06:19:40 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de 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: 12.0 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Oct 2021 06:19:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102540 --- Comment #7 from rguenther at suse dot de --- On Mon, 4 Oct 2021, amacleod at redhat dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102540 >=20 > --- Comment #6 from Andrew Macleod --- >=20 > >=20 > > > It removes a > > > relationship between c_10 and _2. The reason ranger no longer can fol= d _2 =3D=3D 0 > > > is because the sequence is now: > > >=20 > > > a.0_1 =3D a; > > > _2 =3D (unsigned int) a.0_1; > > > b =3D _2; > > > _6 =3D a.0_1 & 4294967295; > > > c_10 =3D _6; > > > if (c_10 !=3D 0) > > > goto ; [INV] > > >=20 > > > We do not find _2 is non-zero on the outgoing edge because _2 is not = related to > > > the calculation in the condition. (ie c_10 no longer has a dependenc= y on _2) > > >=20 > > > We do recalculate _2 based on the outgoing range of a.0_1, but with i= t being a > > > 64 bit value and _2 being 32 bits, we only know the outgoing range of= a.0_1 is > > > non-zero.. we dont track any of the upper bits...=20 > > > 2->3 (T) a.0_1 : long int [-INF, -1][1, +INF] > > > And when we recalculate _2 using that value, we still get varying bec= ause > > > 0xFFFF0000 in not zero, but can still produce a zero in _2. > > >=20 > > > The problem is that the condition c_10 !=3D 0 no longer related to th= e value of > > > _2 in the IL... so ranger never sees it. and we cant represent the 2^= 16 > > > subranges that end in [1,0xFFFF]. > > >=20 > > > Before that transformation,=20 > > > _2 =3D (unsigned int) a.0_1; > > > b =3D _2; > > > c_10 =3D (long int) _2; > > > The relationship is obvious, and ranger would relate the c_10 !=3D 0 = to _2 no > > > problem. > >=20 > > I see - too bad. Note the transform made the dependence chain of _6 > > one instruction shorter without increasing the number of instructions > > so it's a profitable transform. > >=20 > > Btw, the relation is still there but only indirectly via a.0_1. The > > old (E)VRP had this find_asserts(?) that produced assertions based > > on the definitions - sth that now range-ops does(?), so it would > > eventually have built assertions for a.0_1 for both conditions and > > allow relations based on that? I can't seem to find my way around > > the VRP code now - pieces moved all over the place and so my mind > > fails me on the searching task :/ >=20 > We do know that a.0_1 is non-zero on that edge: > 2->3 (T) a.0_1 : long int [-INF, -1][1, +INF] >=20 > the problem is that we can't currently represent that the bitmask operati= on > causes all patterns ending in 0x00000000 to not occur.. we just leave it = at > ~[0,0]. which isn't sufficient for this use case.=20 Hmm, but we do have nonzero bits on SSA where we also store global ranges, so there is a way to store the info and you could intersect the sliced range produced from it with the range you got? > we don't currently track any equivalences between values of different > precision.. (even though ranger once did). Handling it as a general > equivalence was fraught with issues.=20 >=20 > We might be able to add a new equivalence class "slice" or something.. I = had > considered it but hadn't seen a great need case. This would make _6 a 3= 2 bit > slice of a.0_1 with range [1, 0xffffffff]. > Then when we are querying for the cast > _2 =3D (unsigned int) a.0_1; > we could also query the 32 bit equivalence slices of a.0_1, find _6, and = get > the outgoing range of [1,0xffffffff].. and apply that value. >=20 > It would probably resolve an entire class of things where we don't recogn= ize an > equivalence between a cast and a bitmask of equivalent precision. >=20 > This would also mean the reverse would apply.. ie if we instead branched = on _2 > !=3D 0 we would also understand that _6 will be non-zero. I believe tracking known zero/one bits in addition to a range is more useful - would that help in this case?=