mirror of
https://github.com/golang/go
synced 2024-11-24 11:20:07 -07:00
9f291d1fc3
Unlike normal load+op opcodes, the load+compare opcode does not clobber its non-load argument. Allow the load+compare merge to happen even if the non-load argument is used elsewhere. Noticed when investigating issue #28417. Change-Id: Ibc48d1f2e06ae76034c59f453815d263e8ec7288 Reviewed-on: https://go-review.googlesource.com/c/145097 Reviewed-by: Ainar Garipov <gugl.zadolbal@gmail.com> Reviewed-by: Ben Shi <powerman1st@163.com>
96 lines
1.4 KiB
Go
96 lines
1.4 KiB
Go
// 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
|
|
}
|
|
|
|
func compMem3(x, y *int) (int, bool) {
|
|
// We can do comparisons of a register with memory even if
|
|
// the register is used subsequently.
|
|
r := *x
|
|
// amd64:`CMPQ\t\(`
|
|
// 386:`CMPL\t\(`
|
|
return r, r < *y
|
|
}
|