Skip to content

Commit

Permalink
cmd/compile: factor out opIsCommutative from commute1
Browse files Browse the repository at this point in the history
Change-Id: I989a66c98dcca8168e35dd9834fc1365e0a1d881
Reviewed-on: https://go-review.googlesource.com/c/go/+/213697
Run-TryBot: Josh Bleecher Snyder <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
josharian committed Feb 20, 2020
1 parent 06fa4c9 commit 715e8bb
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/cmd/compile/internal/ssa/gen/rulegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,26 +1361,7 @@ func commute1(m string, cnt map[string]int, arch arch) []string {
s := split(m[1 : len(m)-1])
op := s[0]

// Figure out if the op is commutative or not.
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
}
}
}
commutative := opIsCommutative(op, arch)
var idx0, idx1 int
if commutative {
// Find indexes of two args we can swap.
Expand Down Expand Up @@ -1483,3 +1464,26 @@ func normalizeWhitespace(x string) string {
x = strings.Replace(x, ")->", ") ->", -1)
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
}

0 comments on commit 715e8bb

Please sign in to comment.