From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8138B385482A; Fri, 12 Feb 2021 14:43:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8138B385482A From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98028] [8/9/10/11 Regression] __builtin_sub_overflow_p not folded to const when some constraints are known Date: Fri, 12 Feb 2021 14:43:45 +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: missed-optimization 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: 8.5 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: Fri, 12 Feb 2021 14:43:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98028 --- Comment #4 from Andrew Macleod --- I would expect in gcc 12 we'll be handling it differently than that. I have equivalences/relations up and running and will eventually get to applying those to general statements... which I haven't gotten to yet. the gimple_fold() routine uses fold_range () via range-ops to calculate a result. I plan to additionally check if there is a relation between the operands, and if so, invoke another range_ops routine to see if that relati= on makes any further adjustments. in this case, we'd have VARYING - VARYING, so ranges would resolve as expec= ted to VARYING. A query if there is a relation between j_1 and i_2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D j_1(D) unsigned int VARYING i_2(D) unsigned int VARYING Equivalence set : [j_1(D), i_2(D)] : _3 =3D i_2(D) - j_1(D); return _3; shows they are in an equivalence set, so that would be trivial to fold to 0= for MINUS_EXPR. as well, if we see other relations if (j > i) __builtin_unreachable(); return i - j; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 4 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D j_1(D) unsigned int VARYING i_2(D) unsigned int VARYING Relational : (j_1(D) <=3D i_2(D)) : _3 =3D i_2(D) - j_1(D); return _3; it would likewise be pretty straightforward to add the restriction that _3 = will be [0, +INF] (or [1, +INF] if it were j_1 < i_2) If the relation is !=3D, we could also provide ~[0,0] I'd expect the routine for MINUS_EXPR to simply switch on the possible relations and intersect the current result with this reduced possible outco= me. I hope to get most of this in early in stage 1 and we can begin enhancing/finding opportunities. .=