From: Marvin Stenger Date: Wed, 3 May 2017 11:33:14 +0000 (+0200) Subject: cmd/compile/internal/ssa: mark boolean instructions commutative X-Git-Tag: go1.9beta1~299 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9aeced650fec9114433e4c8f990046f7811c9d30;p=gostls13.git cmd/compile/internal/ssa: mark boolean instructions commutative Mark AndB, OrB, EqB, and NeqB as commutative. Change-Id: Ife7cfcb9780cc5dd669617cb52339ab336667da4 Reviewed-on: https://go-review.googlesource.com/42515 Reviewed-by: Giovanni Bajo Reviewed-by: Josh Bleecher Snyder Reviewed-by: Keith Randall Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/ssa/gen/genericOps.go b/src/cmd/compile/internal/ssa/gen/genericOps.go index e9a90963ab..d962e4a193 100644 --- a/src/cmd/compile/internal/ssa/gen/genericOps.go +++ b/src/cmd/compile/internal/ssa/gen/genericOps.go @@ -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 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 32d928388f..938743897e 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -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", diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 72d9c818b2..88cc39a65d 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -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 {