]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssa: mark boolean instructions commutative
authorMarvin Stenger <marvin.stenger94@gmail.com>
Wed, 3 May 2017 11:33:14 +0000 (13:33 +0200)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 9 May 2017 21:31:38 +0000 (21:31 +0000)
Mark AndB, OrB, EqB, and NeqB as commutative.

Change-Id: Ife7cfcb9780cc5dd669617cb52339ab336667da4
Reviewed-on: https://go-review.googlesource.com/42515
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/ssa/gen/genericOps.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/rewritegeneric.go

index e9a90963ab41a2c9a7427d99fa343f915f8da42f..d962e4a193bf8d9663078d3b5843d4df77c32174 100644 (file)
@@ -218,11 +218,11 @@ var genericOps = []opData{
        {name: "Geq64F", argLength: 2, typ: "Bool"},
 
        // boolean ops
-       {name: "AndB", argLength: 2, typ: "Bool"}, // arg0 && arg1 (not shortcircuited)
-       {name: "OrB", argLength: 2, typ: "Bool"},  // arg0 || arg1 (not shortcircuited)
-       {name: "EqB", argLength: 2, typ: "Bool"},  // arg0 == arg1
-       {name: "NeqB", argLength: 2, typ: "Bool"}, // arg0 != arg1
-       {name: "Not", argLength: 1, typ: "Bool"},  // !arg0, boolean
+       {name: "AndB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 && arg1 (not shortcircuited)
+       {name: "OrB", argLength: 2, commutative: true, typ: "Bool"},  // arg0 || arg1 (not shortcircuited)
+       {name: "EqB", argLength: 2, commutative: true, typ: "Bool"},  // arg0 == arg1
+       {name: "NeqB", argLength: 2, commutative: true, typ: "Bool"}, // arg0 != arg1
+       {name: "Not", argLength: 1, typ: "Bool"},                     // !arg0, boolean
 
        // 1-input ops
        {name: "Neg8", argLength: 1}, // -arg0
index 32d928388fa8bbc94f04bb1820bab1b47fbf860e..938743897ee55c7c1b0be5ca0d9eacfc2244da90 100644 (file)
@@ -21751,24 +21751,28 @@ var opcodeTable = [...]opInfo{
                generic: true,
        },
        {
-               name:    "AndB",
-               argLen:  2,
-               generic: true,
+               name:        "AndB",
+               argLen:      2,
+               commutative: true,
+               generic:     true,
        },
        {
-               name:    "OrB",
-               argLen:  2,
-               generic: true,
+               name:        "OrB",
+               argLen:      2,
+               commutative: true,
+               generic:     true,
        },
        {
-               name:    "EqB",
-               argLen:  2,
-               generic: true,
+               name:        "EqB",
+               argLen:      2,
+               commutative: true,
+               generic:     true,
        },
        {
-               name:    "NeqB",
-               argLen:  2,
-               generic: true,
+               name:        "NeqB",
+               argLen:      2,
+               commutative: true,
+               generic:     true,
        },
        {
                name:    "Not",
index 72d9c818b287b2fcff4219db32137c2cb0fab17b..88cc39a65db8566729b2e032f69b34f524af03df 100644 (file)
@@ -7894,6 +7894,24 @@ func rewriteValuegeneric_OpEqB_0(v *Value) bool {
                v.AuxInt = b2i(c == d)
                return true
        }
+       // match: (EqB (ConstBool [d]) (ConstBool [c]))
+       // cond:
+       // result: (ConstBool [b2i(c == d)])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConstBool {
+                       break
+               }
+               d := v_0.AuxInt
+               v_1 := v.Args[1]
+               if v_1.Op != OpConstBool {
+                       break
+               }
+               c := v_1.AuxInt
+               v.reset(OpConstBool)
+               v.AuxInt = b2i(c == d)
+               return true
+       }
        // match: (EqB (ConstBool [0]) x)
        // cond:
        // result: (Not x)
@@ -7910,6 +7928,22 @@ func rewriteValuegeneric_OpEqB_0(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (EqB x (ConstBool [0]))
+       // cond:
+       // result: (Not x)
+       for {
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpConstBool {
+                       break
+               }
+               if v_1.AuxInt != 0 {
+                       break
+               }
+               v.reset(OpNot)
+               v.AddArg(x)
+               return true
+       }
        // match: (EqB (ConstBool [1]) x)
        // cond:
        // result: x
@@ -7927,6 +7961,23 @@ func rewriteValuegeneric_OpEqB_0(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (EqB x (ConstBool [1]))
+       // cond:
+       // result: x
+       for {
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpConstBool {
+                       break
+               }
+               if v_1.AuxInt != 1 {
+                       break
+               }
+               v.reset(OpCopy)
+               v.Type = x.Type
+               v.AddArg(x)
+               return true
+       }
        return false
 }
 func rewriteValuegeneric_OpEqInter_0(v *Value) bool {
@@ -14438,6 +14489,24 @@ func rewriteValuegeneric_OpNeqB_0(v *Value) bool {
                v.AuxInt = b2i(c != d)
                return true
        }
+       // match: (NeqB (ConstBool [d]) (ConstBool [c]))
+       // cond:
+       // result: (ConstBool [b2i(c != d)])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConstBool {
+                       break
+               }
+               d := v_0.AuxInt
+               v_1 := v.Args[1]
+               if v_1.Op != OpConstBool {
+                       break
+               }
+               c := v_1.AuxInt
+               v.reset(OpConstBool)
+               v.AuxInt = b2i(c != d)
+               return true
+       }
        // match: (NeqB (ConstBool [0]) x)
        // cond:
        // result: x
@@ -14455,6 +14524,23 @@ func rewriteValuegeneric_OpNeqB_0(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (NeqB x (ConstBool [0]))
+       // cond:
+       // result: x
+       for {
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpConstBool {
+                       break
+               }
+               if v_1.AuxInt != 0 {
+                       break
+               }
+               v.reset(OpCopy)
+               v.Type = x.Type
+               v.AddArg(x)
+               return true
+       }
        // match: (NeqB (ConstBool [1]) x)
        // cond:
        // result: (Not x)
@@ -14471,6 +14557,22 @@ func rewriteValuegeneric_OpNeqB_0(v *Value) bool {
                v.AddArg(x)
                return true
        }
+       // match: (NeqB x (ConstBool [1]))
+       // cond:
+       // result: (Not x)
+       for {
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpConstBool {
+                       break
+               }
+               if v_1.AuxInt != 1 {
+                       break
+               }
+               v.reset(OpNot)
+               v.AddArg(x)
+               return true
+       }
        return false
 }
 func rewriteValuegeneric_OpNeqInter_0(v *Value) bool {