On 11/1/26 11:13 PM, Jeff Law wrote:
> 
> 
> On 10/27/26 11:44 PM, Naveen SiddeGowda wrote:
>> Hi,
>>
>> Please consider this as a gentle reminder to review the patch at the 
>> following link:-
>> https://gcc.gnu.org/pipermail/gcc-patches/2026-August/729404.html
> Recommend you directly contact Aldy Hernandez and Andrew MacLeod to see if 
> you can get some traction here.
> 
> jeff

I'm inclined to support this, but it needs a few things.

(1)
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -1108,8 +1108,10 @@ gori_compute::refine_using_relation (tree op1, vrange 
&op1_range,
       if (op1_def_p)
        {
          change |= op2_range.intersect (new_result);
-         // Recalculate op2.
-         if (op_handler.fold_range (new_result, type, op2_range, other_op))
+         // Recalculate the LHS passing the lhs-op1 relation so that
+         // operator_plus::fold_range can tighten the no-overflow range.
+         if (op_handler.fold_range (new_result, type, op2_range, other_op,
+                                    relation_trio::lhs_op1 (k)))
            {
              change |= op1_range.intersect (new_result);
            }

We need a better comment communicating why lhs_op1 (k) is valid...  k is 
documented as being the relation between op1 and op2, so perhaps a comment 
preceding these blocks to indicate why we can turn it into a lhs/op1/2 
relation.   maybe something like:

// Note K arrives as an op1/op2 relation, and because of
// the definition chain requirement here, it is also an LHS relation on the
// defining statement, which is how it is passed to the range operators below. 


(2)  under normal circumstances, fold_range would not be able to utilize a 
relation between the LHS and an operand, but there are a few cases, such as 
this, where we can make the argument that it is applicable.   So I think a 
comment in the implementation in fold_range indicating when and why this is 
applicable. recomputations and refinements during GORI calculations when the 
LHS is an already KNOWN value, not just being calculated now.    

 I also think there is some extra code on a hot path here, we should avoid 
doing it if there is no relation,.. it inlines into a quick check...  ie 

  if (!range_operator::fold_range (r, type, lh, rh, rel))
    return false;

  if (r.undefined_p ()
      || !TYPE_UNSIGNED (type)
      || !TYPE_OVERFLOW_WRAPS (type)
      || (rel.lhs_op1 () == VREL_VARYING && rel.lhs_op2 () == VREL_VARYING) 
    return true;

 

(3) The test case has no dg-final — it requests -fdump-tree-optimized and scans 
nothing.. so its not actually testing anything.

Andrew

Reply via email to