compiler: defer to middle-end for complex division

Go used to use slightly different semantics than C99 for complex division,
so we used runtime routines to handle the different.  The gc compiler
has changes its behavior to match C99, so changes ours as well.

For golang/go#14644

Change-Id: I5cad78cf12afe843d2a43cfd0aecc2f5bbca2550
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/274213
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index 23caf61..50574c2 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -6979,27 +6979,6 @@
   // been converted to a String_concat_expression in do_lower.
   go_assert(!left_type->is_string_type());
 
-  // For complex division Go might want slightly different results than the
-  // backend implementation provides, so we have our own runtime routine.
-  if (this->op_ == OPERATOR_DIV && this->left_->type()->complex_type() != NULL)
-    {
-      Runtime::Function complex_code;
-      switch (this->left_->type()->complex_type()->bits())
-	{
-	case 64:
-          complex_code = Runtime::COMPLEX64_DIV;
-	  break;
-	case 128:
-          complex_code = Runtime::COMPLEX128_DIV;
-	  break;
-	default:
-	  go_unreachable();
-	}
-      Expression* complex_div =
-          Runtime::make_call(complex_code, loc, 2, this->left_, this->right_);
-      return complex_div->get_backend(context);
-    }
-
   Bexpression* left = this->left_->get_backend(context);
   Bexpression* right = this->right_->get_backend(context);
 
diff --git a/go/runtime.def b/go/runtime.def
index 9a3c680..4b606a6 100644
--- a/go/runtime.def
+++ b/go/runtime.def
@@ -62,12 +62,6 @@
 	       P2(POINTER, STRING), R1(SLICE))
 
 
-// Complex division.
-DEF_GO_RUNTIME(COMPLEX64_DIV, "__go_complex64_div",
-	       P2(COMPLEX64, COMPLEX64), R1(COMPLEX64))
-DEF_GO_RUNTIME(COMPLEX128_DIV, "__go_complex128_div",
-	       P2(COMPLEX128, COMPLEX128), R1(COMPLEX128))
-
 // Make a slice.
 DEF_GO_RUNTIME(MAKESLICE, "runtime.makeslice", P3(TYPE, INT, INT),
 	       R1(POINTER))
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index f7a163e..4d3e54e 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -439,7 +439,6 @@
 	runtime/go-assert.c \
 	runtime/go-caller.c \
 	runtime/go-callers.c \
-	runtime/go-cdiv.c \
 	runtime/go-cgo.c \
 	runtime/go-construct-map.c \
 	runtime/go-ffi.c \
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index ba202a6..d6ac066 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -240,12 +240,11 @@
 @LIBGO_IS_RTEMS_TRUE@am__objects_3 =  \
 @LIBGO_IS_RTEMS_TRUE@	runtime/rtems-task-variable-add.lo
 am__objects_4 = runtime/aeshash.lo runtime/go-assert.lo \
-	runtime/go-caller.lo runtime/go-callers.lo runtime/go-cdiv.lo \
-	runtime/go-cgo.lo runtime/go-construct-map.lo \
-	runtime/go-ffi.lo runtime/go-fieldtrack.lo \
-	runtime/go-matherr.lo runtime/go-memclr.lo \
-	runtime/go-memequal.lo runtime/go-nanotime.lo \
-	runtime/go-now.lo runtime/go-nosys.lo \
+	runtime/go-caller.lo runtime/go-callers.lo runtime/go-cgo.lo \
+	runtime/go-construct-map.lo runtime/go-ffi.lo \
+	runtime/go-fieldtrack.lo runtime/go-matherr.lo \
+	runtime/go-memclr.lo runtime/go-memequal.lo \
+	runtime/go-nanotime.lo runtime/go-now.lo runtime/go-nosys.lo \
 	runtime/go-reflect-call.lo runtime/go-setenv.lo \
 	runtime/go-signal.lo runtime/go-unsafe-pointer.lo \
 	runtime/go-unsetenv.lo runtime/go-unwind.lo \
@@ -892,7 +891,6 @@
 	runtime/go-assert.c \
 	runtime/go-caller.c \
 	runtime/go-callers.c \
-	runtime/go-cdiv.c \
 	runtime/go-cgo.c \
 	runtime/go-construct-map.c \
 	runtime/go-ffi.c \
@@ -1343,8 +1341,6 @@
 	runtime/$(DEPDIR)/$(am__dirstamp)
 runtime/go-callers.lo: runtime/$(am__dirstamp) \
 	runtime/$(DEPDIR)/$(am__dirstamp)
-runtime/go-cdiv.lo: runtime/$(am__dirstamp) \
-	runtime/$(DEPDIR)/$(am__dirstamp)
 runtime/go-cgo.lo: runtime/$(am__dirstamp) \
 	runtime/$(DEPDIR)/$(am__dirstamp)
 runtime/go-construct-map.lo: runtime/$(am__dirstamp) \
@@ -1417,7 +1413,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-assert.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-caller.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-callers.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-cdiv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-cgo.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-construct-map.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@runtime/$(DEPDIR)/go-context.Plo@am__quote@
diff --git a/libgo/runtime/go-cdiv.c b/libgo/runtime/go-cdiv.c
deleted file mode 100644
index 0355e26..0000000
--- a/libgo/runtime/go-cdiv.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* go-cdiv.c -- complex division routines
-
-   Copyright 2013 The Go Authors. All rights reserved.
-   Use of this source code is governed by a BSD-style
-   license that can be found in the LICENSE file.  */
-
-#include <complex.h>
-#include <math.h>
-
-/* Calls to these functions are generated by the Go frontend for
-   division of complex64 or complex128.  We use these because Go's
-   complex division expects slightly different results from the GCC
-   default.  When dividing NaN+1.0i / 0+0i, Go expects NaN+NaNi but
-   GCC generates NaN+Infi.  NaN+Infi seems wrong seems the rules of
-   C99 Annex G specify that if either side of a complex number is Inf,
-   the the whole number is Inf, but an operation involving NaN ought
-   to result in NaN, not Inf.  */
-
-complex float
-__go_complex64_div (complex float a, complex float b)
-{
-  if (__builtin_expect (b == 0, 0))
-    {
-      if (!isinf (crealf (a))
-	  && !isinf (cimagf (a))
-	  && (isnan (crealf (a)) || isnan (cimagf (a))))
-	{
-	  /* Pass "1" to nanf to match math/bits.go.  */
-	  return nanf("1") + nanf("1")*I;
-	}
-    }
-  return a / b;
-}
-
-complex double
-__go_complex128_div (complex double a, complex double b)
-{
-  if (__builtin_expect (b == 0, 0))
-    {
-      if (!isinf (creal (a))
-	  && !isinf (cimag (a))
-	  && (isnan (creal (a)) || isnan (cimag (a))))
-	{
-	  /* Pass "1" to nan to match math/bits.go.  */
-	  return nan("1") + nan("1")*I;
-	}
-    }
-  return a / b;
-}