passes: wrap memcmp in nosplit function

Along the line of CL 182817, also wrap memcmp.

Also, we don't need to use the wrapper if we are already in a
nosplit function.

Change-Id: I97906c17e0bdc6bbe5d85c923e22c4fadff6d1c1
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/183623
Reviewed-by: Than McIntosh <thanm@google.com>
diff --git a/libgo/runtime/go-wrappers.c b/libgo/runtime/go-wrappers.c
index 6110894..8b4cfd3 100644
--- a/libgo/runtime/go-wrappers.c
+++ b/libgo/runtime/go-wrappers.c
@@ -26,6 +26,12 @@
 	return __builtin_memset(dst, c, n);
 }
 
+int __go_memcmp(const void*, const void*, size_t) __attribute__((no_split_stack));
+int __go_memcmp(const void *a, const void *b, size_t n)
+{
+	return __builtin_memcmp(a, b, n);
+}
+
 // Not no_split_stack -- _Unwind_Resume does use some stack.
 // This wrapper is useful in that it forces a split in here, not in
 // the caller. So the forced split happens only when _Unwind_Resume
diff --git a/passes/GoWrappers.cpp b/passes/GoWrappers.cpp
index 0972a1f..6750c68 100644
--- a/passes/GoWrappers.cpp
+++ b/passes/GoWrappers.cpp
@@ -59,6 +59,9 @@
   if (Disabled)
     return false;
 
+  if (!MF.shouldSplitStack())
+    return false;
+
   for (MachineBasicBlock &MBB : MF)
     for (MachineInstr &MI : MBB)
       if (MI.isCall()) {
@@ -80,6 +83,8 @@
           NewName = "__go_memcpy";
         else if (strcmp(Name, "memset") == 0)
           NewName = "__go_memset";
+        else if (strcmp(Name, "memcmp") == 0)
+          NewName = "__go_memcmp";
         else if (strcmp(Name, "_Unwind_Resume") == 0)
           NewName = "__go_Unwind_Resume";
         else