diff mbox series

[COMMITTED] Provide a routine for NAME == NAME relation.

Message ID 496bc1ca-ab30-6e79-7b00-5dd1fc54b261@redhat.com
State New
Headers show
Series [COMMITTED] Provide a routine for NAME == NAME relation. | expand

Commit Message

Andrew MacLeod Aug. 3, 2023, 6:25 p.m. UTC
We've been assuming x == x is always VREL_EQ in GORI, but this is not 
always going to be true with floating point.  Provide an API to return 
the relation.

Bootstraps on  x86_64-pc-linux-gnu with no regressions.   Pushed.

Andrew
diff mbox series

Patch

From 430ff4f3e670e02185991190a5e2d90e61b39e07 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 2 Aug 2023 10:58:37 -0400
Subject: [PATCH 2/3] Provide a routine for NAME == NAME relation.

We've been assuming x == x s VREL_EQ in GORI, but this is not always going to
be true with floating point.  Provide an API to return the relation.

	* gimple-range-gori.cc (gori_compute::compute_operand1_range):
	Use identity relation.
	(gori_compute::compute_operand2_range): Ditto.
	* value-relation.cc (get_identity_relation): New.
	* value-relation.h (get_identity_relation): New prototype.
---
 gcc/gimple-range-gori.cc | 10 ++++++++--
 gcc/value-relation.cc    | 14 ++++++++++++++
 gcc/value-relation.h     |  3 +++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index 6dc15a0ce3f..c37e54bcf84 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -1142,7 +1142,10 @@  gori_compute::compute_operand1_range (vrange &r,
 
       // If op1 == op2, create a new trio for just this call.
       if (op1 == op2 && gimple_range_ssa_p (op1))
-	trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), VREL_EQ);
+	{
+	  relation_kind k = get_identity_relation (op1, op1_range);
+	  trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), k);
+	}
       if (!handler.calc_op1 (r, lhs, op2_range, trio))
 	return false;
     }
@@ -1218,7 +1221,10 @@  gori_compute::compute_operand2_range (vrange &r,
 
   // If op1 == op2, create a new trio for this stmt.
   if (op1 == op2 && gimple_range_ssa_p (op1))
-    trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), VREL_EQ);
+    {
+      relation_kind k = get_identity_relation (op1, op1_range);
+      trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), k);
+    }
   // Intersect with range for op2 based on lhs and op1.
   if (!handler.calc_op2 (r, lhs, op1_range, trio))
     return false;
diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index 7df2cd6e961..f2c668a0193 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -183,6 +183,20 @@  relation_transitive (relation_kind r1, relation_kind r2)
   return relation_kind (rr_transitive_table[r1][r2]);
 }
 
+// When operands of a statement are identical ssa_names, return the
+// approriate relation between operands for NAME == NAME, given RANGE.
+//
+relation_kind
+get_identity_relation (tree name, vrange &range ATTRIBUTE_UNUSED)
+{
+  // Return VREL_UNEQ when it is supported for floats as appropriate.
+  if (frange::supports_p (TREE_TYPE (name)))
+    return VREL_EQ;
+
+  // Otherwise return VREL_EQ.
+  return VREL_EQ;
+}
+
 // This vector maps a relation to the equivalent tree code.
 
 static const tree_code relation_to_code [VREL_LAST] = {
diff --git a/gcc/value-relation.h b/gcc/value-relation.h
index be6e277421b..f00f84f93b6 100644
--- a/gcc/value-relation.h
+++ b/gcc/value-relation.h
@@ -91,6 +91,9 @@  inline bool relation_equiv_p (relation_kind r)
 
 void print_relation (FILE *f, relation_kind rel);
 
+// Return relation for NAME == NAME with RANGE.
+relation_kind get_identity_relation (tree name, vrange &range);
+
 class relation_oracle
 {
 public:
-- 
2.40.1