1
0
mirror of https://github.com/golang/go synced 2024-11-18 11:55:01 -07:00

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 <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>
This commit is contained in:
Marvin Stenger 2017-05-03 13:33:14 +02:00 committed by Josh Bleecher Snyder
parent 6f2ee0f3df
commit 9aeced650f
3 changed files with 123 additions and 17 deletions

View 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

View 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",

View 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 {