mirror of
https://github.com/golang/go
synced 2024-11-18 00:34:44 -07:00
44fe355694
Ensure that any comparison between two values has the same argument
order. This helps ensure that they can be eliminated during the
lowered CSE pass which will be particularly important if we eliminate
the Greater and Geq ops (see #37316).
Example:
CMP R0, R1
BLT L1
CMP R1, R0 // different order, cannot eliminate
BEQ L2
CMP R0, R1
BLT L1
CMP R0, R1 // same order, can eliminate
BEQ L2
This does have some drawbacks. Notably comparisons might 'flip'
direction in the assembly output after even small changes to the
code or compiler. It should help make optimizations more reliable
however.
compilecmp master -> HEAD
master (218f4572f5
): text/template: make reflect.Value indirections more robust
HEAD (f1661fef3e): cmd/compile: canonicalize comparison argument order
platform: linux/amd64
file before after Δ %
api 6063927 6068023 +4096 +0.068%
asm 5191757 5183565 -8192 -0.158%
cgo 4893518 4901710 +8192 +0.167%
cover 5330345 5326249 -4096 -0.077%
fix 3417778 3421874 +4096 +0.120%
pprof 14889456 14885360 -4096 -0.028%
test2json 2848138 2844042 -4096 -0.144%
trace 11746239 11733951 -12288 -0.105%
total 132739173 132722789 -16384 -0.012%
Change-Id: I11736b3fe2a4553f6fc65018f475e88217fa22f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/220425
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
155 lines
2.8 KiB
Go
155 lines
2.8 KiB
Go
// asmcheck
|
|
|
|
// Copyright 2019 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
|
|
|
|
//go:noinline
|
|
func dummy() {}
|
|
|
|
// Signed 64-bit compare-and-branch.
|
|
func si64(x, y chan int64) {
|
|
// s390x:"CGRJ\t[$](2|4), R[0-9]+, R[0-9]+, "
|
|
for <-x < <-y {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CL?GRJ\t[$]8, R[0-9]+, R[0-9]+, "
|
|
for <-x == <-y {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Signed 64-bit compare-and-branch with 8-bit immediate.
|
|
func si64x8() {
|
|
// s390x:"CGIJ\t[$]12, R[0-9]+, [$]127, "
|
|
for i := int64(0); i < 128; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CGIJ\t[$]10, R[0-9]+, [$]-128, "
|
|
for i := int64(0); i > -129; i-- {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CGIJ\t[$]2, R[0-9]+, [$]127, "
|
|
for i := int64(0); i >= 128; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CGIJ\t[$]4, R[0-9]+, [$]-128, "
|
|
for i := int64(0); i <= -129; i-- {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Unsigned 64-bit compare-and-branch.
|
|
func ui64(x, y chan uint64) {
|
|
// s390x:"CLGRJ\t[$](2|4), R[0-9]+, R[0-9]+, "
|
|
for <-x > <-y {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CL?GRJ\t[$]6, R[0-9]+, R[0-9]+, "
|
|
for <-x != <-y {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Unsigned 64-bit comparison with 8-bit immediate.
|
|
func ui64x8() {
|
|
// s390x:"CLGIJ\t[$]4, R[0-9]+, [$]128, "
|
|
for i := uint64(0); i < 128; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CLGIJ\t[$]12, R[0-9]+, [$]255, "
|
|
for i := uint64(0); i < 256; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CLGIJ\t[$]2, R[0-9]+, [$]255, "
|
|
for i := uint64(0); i >= 256; i-- {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CLGIJ\t[$]2, R[0-9]+, [$]0, "
|
|
for i := uint64(1024); i > 0; i-- {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Signed 32-bit compare-and-branch.
|
|
func si32(x, y chan int32) {
|
|
// s390x:"CRJ\t[$](2|4), R[0-9]+, R[0-9]+, "
|
|
for <-x < <-y {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CL?RJ\t[$]8, R[0-9]+, R[0-9]+, "
|
|
for <-x == <-y {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Signed 32-bit compare-and-branch with 8-bit immediate.
|
|
func si32x8() {
|
|
// s390x:"CIJ\t[$]12, R[0-9]+, [$]127, "
|
|
for i := int32(0); i < 128; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CIJ\t[$]10, R[0-9]+, [$]-128, "
|
|
for i := int32(0); i > -129; i-- {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CIJ\t[$]2, R[0-9]+, [$]127, "
|
|
for i := int32(0); i >= 128; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CIJ\t[$]4, R[0-9]+, [$]-128, "
|
|
for i := int32(0); i <= -129; i-- {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Unsigned 32-bit compare-and-branch.
|
|
func ui32(x, y chan uint32) {
|
|
// s390x:"CLRJ\t[$](2|4), R[0-9]+, R[0-9]+, "
|
|
for <-x > <-y {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CL?RJ\t[$]6, R[0-9]+, R[0-9]+, "
|
|
for <-x != <-y {
|
|
dummy()
|
|
}
|
|
}
|
|
|
|
// Unsigned 32-bit comparison with 8-bit immediate.
|
|
func ui32x8() {
|
|
// s390x:"CLIJ\t[$]4, R[0-9]+, [$]128, "
|
|
for i := uint32(0); i < 128; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CLIJ\t[$]12, R[0-9]+, [$]255, "
|
|
for i := uint32(0); i < 256; i++ {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CLIJ\t[$]2, R[0-9]+, [$]255, "
|
|
for i := uint32(0); i >= 256; i-- {
|
|
dummy()
|
|
}
|
|
|
|
// s390x:"CLIJ\t[$]2, R[0-9]+, [$]0, "
|
|
for i := uint32(1024); i > 0; i-- {
|
|
dummy()
|
|
}
|
|
}
|