From 9c739c9893ca6af841e7c67cce0ad9c17a248d13 Mon Sep 17 00:00:00 2001
From: Aldy Hernandez <aldyh@redhat.com>
Date: Fri, 15 Sep 2023 08:24:24 -0400
Subject: [PATCH] [frange] Add op2_range for operator_not_equal.

We're missing an op2_range entry for operator_not_equal so GORI can
calculate an outgoing edge.  The false side of != is true and
guarantees we don't have a NAN, so it's important to get this right.
We eventually get it through an intersection of various ranges in
ranger, but it's best to get things correct as early as possible.

gcc/ChangeLog:

	* range-op-float.cc (operator_not_equal::op2_range): New.
	* range-op-mixed.h: Add operator_not_equal::op2_range.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/vrp-float-13.c: New test.
---
 gcc/range-op-float.cc                        |  8 ++++++++
 gcc/range-op-mixed.h                         |  3 +++
 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-13.c | 16 ++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-float-13.c

diff --git a/gcc/range-op-float.cc b/gcc/range-op-float.cc
index cc729e12a9ec..91d3096fdac4 100644
--- a/gcc/range-op-float.cc
+++ b/gcc/range-op-float.cc
@@ -900,6 +900,14 @@ operator_not_equal::op1_range (frange &r, tree type,
   return true;
 }
 
+bool
+operator_not_equal::op2_range (frange &r, tree type,
+			       const irange &lhs,
+			       const frange &op1,
+			       relation_trio trio) const
+{
+  return op1_range (r, type, lhs, op1, trio);
+}
 
 // Check if the LHS range indicates a relation between OP1 and OP2.
 
diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h
index ef562326c1f7..f7ff47b27259 100644
--- a/gcc/range-op-mixed.h
+++ b/gcc/range-op-mixed.h
@@ -164,6 +164,9 @@ public:
   bool op2_range (irange &r, tree type,
 		  const irange &lhs, const irange &op1,
 		  relation_trio = TRIO_VARYING) const final override;
+  bool op2_range (frange &r, tree type,
+		  const irange &lhs, const frange &op1,
+		  relation_trio = TRIO_VARYING) const final override;
 
   relation_kind op1_op2_relation (const irange &lhs, const irange &,
 				  const irange &) const final override;
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-13.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-13.c
new file mode 100644
index 000000000000..f5a0164dd91b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-13.c
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-O2 -fno-thread-jumps -fdisable-tree-fre1 -fdump-tree-evrp-details" }
+
+void a(float, float);
+void b(float, float);
+
+void foo(float x, float y)
+{
+  if (x != y)
+    a (x,y);
+  else if (x < y)
+    b (x,y);
+}
+
+// Test that the false side of if(x != y) has a range for y.
+// { dg-final { scan-tree-dump "2->4  \\(F\\) y_3\\(D\\)" "evrp" } }
-- 
GitLab