mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: implement comparisons directly with memory
Allow the compiler to generate code like CMPQ 16(AX), $7 It's tricky because it's difficult to spill such a comparison during flagalloc, because the same memory state might not be available at the restore locations. Solve this problem by decomposing the compare+load back into its parts if it needs to be spilled. The big win is that the write barrier test goes from: MOVL runtime.writeBarrier(SB), CX TESTL CX, CX JNE 60 to CMPL runtime.writeBarrier(SB), $0 JNE 59 It's one instruction and one byte smaller. Fixes #19485 Fixes #15245 Update #22460 Binaries are about 0.15% smaller. Change-Id: I4fd8d1111b6b9924d52f9a0901ca1b2e5cce0836 Reviewed-on: https://go-review.googlesource.com/86035 Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ilya Tocar <ilya.tocar@intel.com>
This commit is contained in:
parent
30673769ed
commit
4b00d3f4a2
9 changed files with 1029 additions and 16 deletions
|
|
@ -923,14 +923,14 @@ var linuxAMD64Tests = []*asmTest{
|
|||
func f65(a string) bool {
|
||||
return a == "xx"
|
||||
}`,
|
||||
pos: []string{"\tCMPW\t[A-Z]"},
|
||||
pos: []string{"\tCMPW\t\\(.*\\), [$]"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func f66(a string) bool {
|
||||
return a == "xxxx"
|
||||
}`,
|
||||
pos: []string{"\tCMPL\t[A-Z]"},
|
||||
pos: []string{"\tCMPL\t\\(.*\\), [$]"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
|
|
@ -1002,42 +1002,51 @@ var linuxAMD64Tests = []*asmTest{
|
|||
func f68(a,b [2]byte) bool {
|
||||
return a == b
|
||||
}`,
|
||||
pos: []string{"\tCMPW\t[A-Z]"},
|
||||
pos: []string{"\tCMPW\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func f69(a,b [3]uint16) bool {
|
||||
return a == b
|
||||
}`,
|
||||
pos: []string{"\tCMPL\t[A-Z]"},
|
||||
pos: []string{
|
||||
"\tCMPL\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
|
||||
"\tCMPW\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
|
||||
},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(a,b [3]int16) bool {
|
||||
return a == b
|
||||
}`,
|
||||
pos: []string{"\tCMPL\t[A-Z]"},
|
||||
pos: []string{
|
||||
"\tCMPL\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
|
||||
"\tCMPW\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
|
||||
},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(a,b [12]int8) bool {
|
||||
return a == b
|
||||
}`,
|
||||
pos: []string{"\tCMPQ\t[A-Z]", "\tCMPL\t[A-Z]"},
|
||||
pos: []string{
|
||||
"\tCMPQ\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
|
||||
"\tCMPL\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
|
||||
},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func f70(a,b [15]byte) bool {
|
||||
return a == b
|
||||
}`,
|
||||
pos: []string{"\tCMPQ\t[A-Z]"},
|
||||
pos: []string{"\tCMPQ\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func f71(a,b unsafe.Pointer) bool { // This was a TODO in mapaccess1_faststr
|
||||
return *((*[4]byte)(a)) != *((*[4]byte)(b))
|
||||
}`,
|
||||
pos: []string{"\tCMPL\t[A-Z]"},
|
||||
pos: []string{"\tCMPL\t\\(.*\\), [A-Z]"},
|
||||
},
|
||||
{
|
||||
// make sure assembly output has matching offset and base register.
|
||||
|
|
@ -1767,6 +1776,46 @@ var linuxAMD64Tests = []*asmTest{
|
|||
`,
|
||||
neg: []string{"TESTB"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(p int, q *int) bool {
|
||||
return p < *q
|
||||
}
|
||||
`,
|
||||
pos: []string{"CMPQ\t\\(.*\\), [A-Z]"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(p *int, q int) bool {
|
||||
return *p < q
|
||||
}
|
||||
`,
|
||||
pos: []string{"CMPQ\t\\(.*\\), [A-Z]"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(p *int) bool {
|
||||
return *p < 7
|
||||
}
|
||||
`,
|
||||
pos: []string{"CMPQ\t\\(.*\\), [$]7"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(p *int) bool {
|
||||
return 7 < *p
|
||||
}
|
||||
`,
|
||||
pos: []string{"CMPQ\t\\(.*\\), [$]7"},
|
||||
},
|
||||
{
|
||||
fn: `
|
||||
func $(p **int) {
|
||||
*p = nil
|
||||
}
|
||||
`,
|
||||
pos: []string{"CMPL\truntime.writeBarrier\\(SB\\), [$]0"},
|
||||
},
|
||||
}
|
||||
|
||||
var linux386Tests = []*asmTest{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue