cmd/compile: don't write back unchanged slice results

Don't write back parts of a slicing operation if they
are unchanged from the source of the slice.  For example:

x.s = x.s[0:5]         // don't write back pointer or cap
x.s = x.s[:5]          // don't write back pointer or cap
x.s = x.s[:5:7]        // don't write back pointer

There is more to be done here, for example:

x.s = x.s[:len(x.s):7] // don't write back ptr or len

This CL can't handle that one yet.

Fixes #14855

Change-Id: Id1e1a4fa7f3076dc1a76924a7f1cd791b81909bb
Reviewed-on: https://go-review.googlesource.com/20954
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
diff --git a/test/writebarrier.go b/test/writebarrier.go
index 7510728..44e42f0 100644
--- a/test/writebarrier.go
+++ b/test/writebarrier.go
@@ -176,8 +176,9 @@
 
 func f18(p *T18, x *[]int) {
 	p.a = p.a[:5]    // no barrier
-	p.a = p.a[3:5]   // no barrier
-	p.a = p.a[1:2:3] // no barrier
-	p.s = p.s[8:9]   // no barrier
-	*x = (*x)[3:5]   // no barrier
+	*x = (*x)[0:5]   // no barrier
+	p.a = p.a[3:5]   // ERROR "write barrier"
+	p.a = p.a[1:2:3] // ERROR "write barrier"
+	p.s = p.s[8:9]   // ERROR "write barrier"
+	*x = (*x)[3:5]   // ERROR "write barrier"
 }