Commit b1f656b1 authored by Keith Randall's avatar Keith Randall

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/135379Reviewed-by: default avatarIlya Tocar <ilya.tocar@intel.com>
parent a708353a
......@@ -1042,6 +1042,11 @@
((ADD|SUB|AND|OR|XOR)Qload [off1+off2] {sym} val base mem)
((ADD|SUB|AND|OR|XOR)Lload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) ->
((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {sym} val base mem)
(CMP(Q|L|W|B)load [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) ->
(CMP(Q|L|W|B)load [off1+off2] {sym} base val mem)
(CMP(Q|L|W|B)constload [off1] {sym} (ADDQconst [off2] base) mem) && is32Bit(off1+off2) ->
(CMP(Q|L|W|B)constload [off1+off2] {sym} base mem)
((ADD|SUB|MUL|DIV)SSload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) ->
((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem)
((ADD|SUB|MUL|DIV)SDload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) ->
......@@ -1088,6 +1093,13 @@
((ADD|SUB|AND|OR|XOR)Lload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem)
&& is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {mergeSym(sym1,sym2)} val base mem)
(CMP(Q|L|W|B)load [off1] {sym1} (LEAQ [off2] {sym2} base) val mem)
&& is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
(CMP(Q|L|W|B)load [off1+off2] {mergeSym(sym1,sym2)} base val mem)
(CMP(Q|L|W|B)constload [off1] {sym1} (LEAQ [off2] {sym2} base) mem)
&& is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
(CMP(Q|L|W|B)constload [off1+off2] {mergeSym(sym1,sym2)} base mem)
((ADD|SUB|MUL|DIV)SSload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem)
&& is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
((ADD|SUB|MUL|DIV)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem)
......
// 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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment