public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [range-ops] Implement sqrt.
@ 2022-11-13 20:05 Aldy Hernandez
  2022-11-13 20:39 ` Jakub Jelinek
  0 siblings, 1 reply; 21+ messages in thread
From: Aldy Hernandez @ 2022-11-13 20:05 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC patches, Andrew MacLeod, Aldy Hernandez

It seems SQRT is relatively straightforward, and it's something Jakub
wanted for this release.

Jakub, what do you think?

p.s. Too tired to think about op1_range.

gcc/ChangeLog:

	* gimple-range-op.cc (class cfn_sqrt): New.
	(gimple_range_op_handler::maybe_builtin_call): Add cases for sqrt.
---
 gcc/gimple-range-op.cc | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
index 7764166d5fb..240cd8b6a11 100644
--- a/gcc/gimple-range-op.cc
+++ b/gcc/gimple-range-op.cc
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "range.h"
 #include "value-query.h"
 #include "gimple-range.h"
+#include "fold-const-call.h"
 
 // Given stmt S, fill VEC, up to VEC_SIZE elements, with relevant ssa-names
 // on the statement.  For efficiency, it is an error to not pass in enough
@@ -301,6 +302,41 @@ public:
   }
 } op_cfn_constant_p;
 
+// Implement range operator for SQRT.
+class cfn_sqrt : public range_operator_float
+{
+  using range_operator_float::fold_range;
+private:
+  REAL_VALUE_TYPE real_sqrt (const REAL_VALUE_TYPE &arg, tree type) const
+  {
+    tree targ = build_real (type, arg);
+    tree res = fold_const_call (as_combined_fn (BUILT_IN_SQRT), type, targ);
+    return *TREE_REAL_CST_PTR (res);
+  }
+  void rv_fold (REAL_VALUE_TYPE &lb, REAL_VALUE_TYPE &ub, bool &maybe_nan,
+		tree type,
+		const REAL_VALUE_TYPE &lh_lb,
+		const REAL_VALUE_TYPE &lh_ub,
+		const REAL_VALUE_TYPE &,
+		const REAL_VALUE_TYPE &,
+		relation_kind) const final override
+  {
+    if (real_compare (LT_EXPR, &lh_ub, &dconst0))
+      {
+	real_nan (&lb, "", 0, TYPE_MODE (type));
+	ub = lb;
+	maybe_nan = true;
+	return;
+      }
+    lb = real_sqrt (lh_lb, type);
+    ub = real_sqrt (lh_ub, type);
+    if (real_compare (GE_EXPR, &lh_lb, &dconst0))
+      maybe_nan = false;
+    else
+      maybe_nan = true;
+  }
+} fop_cfn_sqrt;
+
 // Implement range operator for CFN_BUILT_IN_SIGNBIT.
 class cfn_signbit : public range_operator_float
 {
@@ -907,6 +943,12 @@ gimple_range_op_handler::maybe_builtin_call ()
       m_int = &op_cfn_parity;
       break;
 
+    CASE_CFN_SQRT:
+    CASE_CFN_SQRT_FN:
+      m_valid = true;
+      m_float = &fop_cfn_sqrt;
+      break;
+
     default:
       break;
     }
-- 
2.38.1


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-11-18 12:14 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-13 20:05 [PATCH] [range-ops] Implement sqrt Aldy Hernandez
2022-11-13 20:39 ` Jakub Jelinek
2022-11-14  7:45   ` Aldy Hernandez
2022-11-14 14:30     ` Jeff Law
2022-11-14 14:35       ` Jakub Jelinek
2022-11-14 14:48         ` Jeff Law
2022-11-14 15:01         ` Aldy Hernandez
2022-11-14 21:55   ` Joseph Myers
2022-11-16 20:32     ` Jakub Jelinek
2022-11-17 16:40       ` Aldy Hernandez
2022-11-17 16:48         ` Aldy Hernandez
2022-11-17 17:42           ` Aldy Hernandez
2022-11-17 18:59         ` Joseph Myers
2022-11-17 19:37           ` Jakub Jelinek
2022-11-17 20:43             ` Joseph Myers
2022-11-18  8:39             ` Richard Biener
2022-11-18 10:37               ` Aldy Hernandez
2022-11-18 10:44                 ` Jakub Jelinek
2022-11-18 11:20                   ` Aldy Hernandez
2022-11-18 11:57                     ` Aldy Hernandez
2022-11-18 12:14                   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).