When auditing the code, I noticed that
gimple_range_fold::range_of_range_op was reusing a local variable when
it shouldn't.
It was picking up a relation between op1 and op2, and using that
relation to assist in determining if there was a new relation being
formed bet6ween LHS and op1/op2.
I was reusing the same local variable, so when determining if there was
a relation between LHS and OP1, that was then being passed on to the
query for LHS and OP2.
I don't think we are likely to see a bug as a result, its more likely to
be a missed opportunity to register a relation between LHS and OP2...
so I dont think it needs back porting at this point... although it would
be harmless to do so.
Bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed.
Andrew
From 1df77858cac29c71fc29bc6571e17d3b26d9d176 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacl...@redhat.com>
Date: Tue, 22 Apr 2025 13:52:45 -0400
Subject: [PATCH 4/9] Do not overwrite relation in range_of_range_op.
when registering reltions between the lhs and op1/op2, the relation
between op1 and op2 is being overwritten by the result. This could
result in either an incorrect relation being registered between lhs and op2,
or a correct relation not being recognized.
* gimple-range-fold.cc (fold_using_range::range_of_range_op): Use a
new local variable for intermediate relation results.
---
gcc/gimple-range-fold.cc | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 3bb24d58940..aed5c7dc21e 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -759,15 +759,17 @@ fold_using_range::range_of_range_op (vrange &r,
}
if (gimple_range_ssa_p (op1))
{
- rel = handler.lhs_op1_relation (r, range1, range2, rel);
- if (rel != VREL_VARYING)
- src.register_relation (s, rel, lhs, op1);
+ relation_kind rel2 = handler.lhs_op1_relation (r, range1,
+ range2, rel);
+ if (rel2 != VREL_VARYING)
+ src.register_relation (s, rel2, lhs, op1);
}
if (gimple_range_ssa_p (op2))
{
- rel = handler.lhs_op2_relation (r, range1, range2, rel);
- if (rel != VREL_VARYING)
- src.register_relation (s, rel, lhs, op2);
+ relation_kind rel2 = handler.lhs_op2_relation (r, range1,
+ range2, rel);
+ if (rel2 != VREL_VARYING)
+ src.register_relation (s, rel2, lhs, op2);
}
}
// Check for an existing BB, as we maybe asked to fold an
--
2.45.0