1
0
mirror of https://github.com/golang/go synced 2024-11-17 21:54:49 -07:00

cmd/compile: factor out opIsCommutative from commute1

Change-Id: I989a66c98dcca8168e35dd9834fc1365e0a1d881
Reviewed-on: https://go-review.googlesource.com/c/go/+/213697
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2020-01-06 13:14:03 -08:00
parent 06fa4c9589
commit 715e8bbe63

View File

@ -1361,26 +1361,7 @@ func commute1(m string, cnt map[string]int, arch arch) []string {
s := split(m[1 : len(m)-1]) s := split(m[1 : len(m)-1])
op := s[0] op := s[0]
// Figure out if the op is commutative or not. commutative := opIsCommutative(op, arch)
commutative := false
for _, x := range genericOps {
if op == x.name {
if x.commutative {
commutative = true
}
break
}
}
if arch.name != "generic" {
for _, x := range arch.ops {
if op == x.name {
if x.commutative {
commutative = true
}
break
}
}
}
var idx0, idx1 int var idx0, idx1 int
if commutative { if commutative {
// Find indexes of two args we can swap. // Find indexes of two args we can swap.
@ -1483,3 +1464,26 @@ func normalizeWhitespace(x string) string {
x = strings.Replace(x, ")->", ") ->", -1) x = strings.Replace(x, ")->", ") ->", -1)
return x return x
} }
// opIsCommutative reports whether op s is commutative.
func opIsCommutative(op string, arch arch) bool {
for _, x := range genericOps {
if op == x.name {
if x.commutative {
return true
}
break
}
}
if arch.name != "generic" {
for _, x := range arch.ops {
if op == x.name {
if x.commutative {
return true
}
break
}
}
}
return false
}