From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 30368388C01F; Tue, 5 Jan 2021 15:55:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30368388C01F From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98513] [10/11 Regression] Wrong code with -O3 since r10-2804-gbf05a3bbb58b3558 Date: Tue, 05 Jan 2021 15:55:24 +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: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.3 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 Jan 2021 15:55:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98513 --- Comment #7 from Andrew Macleod --- This is in the legacy intersection code=20 we have [-INF, minus_1_29(D) + 2] intersect [ -INF + 1, -INF + 2] it falls into this block: else if ((operand_less_p (vr1min, *vr0max) =3D=3D 1 || operand_equal_p (vr1min, *vr0max, 0)) && operand_less_p (*vr0min, vr1min) =3D=3D 1) { /* [ ( ] ) or [ ]( ) */ if (*vr0type =3D=3D VR_ANTI_RANGE && vr1type =3D=3D VR_ANTI_RANGE) *vr0max =3D vr1max; else if (*vr0type =3D=3D VR_RANGE && vr1type =3D=3D VR_RANGE) *vr0min =3D vr1min; else if (*vr0type =3D=3D VR_RANGE && vr1type =3D=3D VR_ANTI_RANGE) { if (TREE_CODE (vr1min) =3D=3D INTEGER_CST) --> *vr0max =3D int_const_binop (MINUS_EXPR, vr1min, build_int_cst (TREE_TYPE (vr1min), 1= )); else *vr0max =3D vr1min; } (gdb) p operand_less_p (vr1min, *vr0max) $19 =3D 1 (gdb) p operand_less_p (*vr0min, vr1min) $21 =3D 1 and ends up setting vr0max to (vr1min - 1), which is -INF and so returns [-INF, -INF] It seems like it *should* have entered an earlier hunk here maybe? else if ((maxeq || operand_less_p (vr1max, *vr0max) =3D=3D 1) && (mineq || operand_less_p (*vr0min, vr1min) =3D=3D 1)) { /* [ ( ) ] or [( ) ] or [ ( )] */ this looks like the [ ( ) ] case? if I interpret this correctly it fails to enter this block because: (gdb) p operand_less_p (vr1max, *vr0max) $22 =3D -2 which is operand_less_p (-INF + 2, minus_1_29(D) + 2) so it claims they cannot be compared at compile time, and thus doesn't drop into this block.=20 Im not sure what should be done here... The easiest thing to do is simply p= unt when we get a -2 back anywhere... and leave vr0 as it is. thats conservative and safe. Im not even sure how best to add those checks in where needed. Otherwise we'll have to delve into why we got a -2, and eventually maybe substitute +INF for vr0max... but really, I think you'd have to do that so= rt of check for each of the operand_less_p() calls to be correct, and figure = out when you want to substitute a +INF or -INF and recalculate the expression. Although maybe you have a more concise idea of how to handle this. Perhaps= its more localized than it appears to me at first glance.=