aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/memops.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2018-09-14 10:57:57 -0700
committerKeith Randall <khr@golang.org>2018-09-14 19:42:09 +0000
commitb1f656b1ceb09124f2d8ad63ceceb8df20a581c2 (patch)
tree4c31a6cfc9f08487780c9d3481785e9910bf95d0 /test/codegen/memops.go
parenta708353a0c2c39ce4e8182ea75e5082135ae674f (diff)
downloadgo-b1f656b1ceb09124f2d8ad63ceceb8df20a581c2.tar.xz
cmd/compile: fold address calculations into CMPload[const] ops
Makes go binary smaller by 0.2%. I noticed this in autogenerated equal methods, and there are probably a lot of those. Change-Id: I4e04eb3653fbceb9dd6a4eee97ceab1fa4d10b72 Reviewed-on: https://go-review.googlesource.com/135379 Reviewed-by: Ilya Tocar <ilya.tocar@intel.com>
Diffstat (limited to 'test/codegen/memops.go')
-rw-r--r--test/codegen/memops.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/test/codegen/memops.go b/test/codegen/memops.go
new file mode 100644
index 0000000000..223375ac11
--- /dev/null
+++ b/test/codegen/memops.go
@@ -0,0 +1,86 @@
+// asmcheck
+
+// Copyright 2018 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.
+
+package codegen
+
+var x [2]bool
+var x8 [2]uint8
+var x16 [2]uint16
+var x32 [2]uint32
+var x64 [2]uint64
+
+func compMem1() int {
+ // amd64:`CMPB\t"".x\+1\(SB\), [$]0`
+ if x[1] {
+ return 1
+ }
+ // amd64:`CMPB\t"".x8\+1\(SB\), [$]7`
+ if x8[1] == 7 {
+ return 1
+ }
+ // amd64:`CMPW\t"".x16\+2\(SB\), [$]7`
+ if x16[1] == 7 {
+ return 1
+ }
+ // amd64:`CMPL\t"".x32\+4\(SB\), [$]7`
+ if x32[1] == 7 {
+ return 1
+ }
+ // amd64:`CMPQ\t"".x64\+8\(SB\), [$]7`
+ if x64[1] == 7 {
+ return 1
+ }
+ return 0
+}
+
+//go:noinline
+func f(x int) bool {
+ return false
+}
+
+//go:noinline
+func f8(x int) int8 {
+ return 0
+}
+
+//go:noinline
+func f16(x int) int16 {
+ return 0
+}
+
+//go:noinline
+func f32(x int) int32 {
+ return 0
+}
+
+//go:noinline
+func f64(x int) int64 {
+ return 0
+}
+
+func compMem2() int {
+ // amd64:`CMPB\t8\(SP\), [$]0`
+ if f(3) {
+ return 1
+ }
+ // amd64:`CMPB\t8\(SP\), [$]7`
+ if f8(3) == 7 {
+ return 1
+ }
+ // amd64:`CMPW\t8\(SP\), [$]7`
+ if f16(3) == 7 {
+ return 1
+ }
+ // amd64:`CMPL\t8\(SP\), [$]7`
+ if f32(3) == 7 {
+ return 1
+ }
+ // amd64:`CMPQ\t8\(SP\), [$]7`
+ if f64(3) == 7 {
+ return 1
+ }
+ return 0
+}