]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: factor out opIsCommutative from commute1
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 6 Jan 2020 21:14:03 +0000 (13:14 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 20 Feb 2020 03:27:46 +0000 (03:27 +0000)
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>
src/cmd/compile/internal/ssa/gen/rulegen.go

index 444a8566c64f78ea2ad35399ff3d3431d561205d..2fca70f40b37630b4a430a60afab6dadd240f1e8 100644 (file)
@@ -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.
@@ -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
+}