From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C26403857C72; Tue, 12 Dec 2023 21:59:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C26403857C72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702418347; bh=Jq3Jl3hcYKkzoJ90GNUd01uiilo3Dl7g4NHRd4KyGRI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xyiLBwQUjV3kMSVjgrVcLAMZLuDS0niGfl3KNaHGF8VDVHXFQIWlJRi0CE/haYe9C qpHYxsluEJd7Z1CHHfYP2s28/FQAz9jo4V+xnO+H70KVULfd8pqbkFVnu31TQza2KB iZSdaEVeI8TJSxVOWz07nRilrSFlqt0r1Arw74oo= From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/110199] [12/13/14 Regression] Missing VRP transformation with MIN_EXPR and known relation Date: Tue, 12 Dec 2023 21:59:06 +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: 14.0 X-Bugzilla-Keywords: missed-optimization, needs-bisection X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.4 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=3D110199 --- Comment #3 from Andrew Macleod --- (In reply to Andrew Pinski from comment #2) > I Kinda see how to implement this by creating > operator_min::fold_range/operator_max::fold_range but I am still new on > using these interfaces so I am not 100% sure how to use them. Actually, on ranger, we'd be able to make the range choice of the range of = a_2 or b_3, but it can't rewrite the IL... and since the range of both is vary= ing, fold_range would still return varying. Unless we indicate there are relati= ons. fodl_range itself only takes what it is given, so we have to query the relations first.=20 In theory all that is missing is to teach simplification about relation queries. For instance, in simplify_using_ranges::fold_cond_with_ops, we are invoking the range-op handler without any relations.. we query the ranges, = but not the relation. If we add something like this (and make sure both operands are symbolic) diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index ecb294131b0..ad2c2d6c090 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -315,10 +315,17 @@ simplify_using_ranges::fold_cond_with_ops (enum tree_= code code, || !query->range_of_expr (r1, op1, s)) return NULL_TREE; + relation_kind rel =3D VREL_VARYING; + if (gimple_range_ssa_p (op0) && gimple_range_ssa_p (op1)) + rel =3D query->query_relation (s, op0, op1); + // Create a trio with the relation set between op0 and op2 for folding. + // TRIOS are lhs-op0, lhs-op1, op0-op1 relations. + relation_trio trio (VREL_VARYING, VREL_VARYING, rel); + tree type =3D TREE_TYPE (op0); int_range<1> res; range_op_handler handler (code); - if (handler && handler.fold_range (res, type, r0, r1)) + if (handler && handler.fold_range (res, type, r0, r1, trio)) { if (res =3D=3D range_true (type)) return boolean_true_node; This should do what you want I think... fold_range should use the relation passed in to determine that the condition is always true or false. I have not fully tested this patch, fwiw.=