https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110199
--- Comment #3 from Andrew Macleod <amacleod at redhat dot com> --- (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 varying, fold_range would still return varying. Unless we indicate there are relations. fodl_range itself only takes what it is given, so we have to query the relations first. 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 = VREL_VARYING; + if (gimple_range_ssa_p (op0) && gimple_range_ssa_p (op1)) + rel = 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 = 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 == 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.