cmd/compile: replace boolean simplification rule

Replace one of the boolean simplification rules with two new rules
in order to cover more cases.

This is a rebase of CL 42516 which slipped through the cracks.

Change-Id: I6da4cf30e5156174e8eac6bc2f0e2cebe95e555c
Reviewed-on: https://go-review.googlesource.com/c/go/+/750520
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
This commit is contained in:
Marvin Stenger
2017-05-03 13:36:13 +02:00
committed by Gopher Robot
parent 74e9214b53
commit cb41169895
2 changed files with 21 additions and 8 deletions

View File

@@ -277,12 +277,13 @@
(EqB (ConstBool [c]) (ConstBool [d])) => (ConstBool [c == d])
(EqB (ConstBool [false]) x) => (Not x)
(EqB (ConstBool [true]) x) => x
(EqB (Not x) y) => (NeqB x y)
(Neq(64|32|16|8|B) x x) => (ConstBool [false])
(NeqB (ConstBool [c]) (ConstBool [d])) => (ConstBool [c != d])
(NeqB (ConstBool [false]) x) => x
(NeqB (ConstBool [true]) x) => (Not x)
(NeqB (Not x) (Not y)) => (NeqB x y)
(NeqB (Not x) y) => (EqB x y)
(Eq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x)) => (Eq64 (Const64 <t> [c-d]) x)
(Eq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x)) => (Eq32 (Const32 <t> [c-d]) x)

View File

@@ -8544,6 +8544,21 @@ func rewriteValuegeneric_OpEqB(v *Value) bool {
}
break
}
// match: (EqB (Not x) y)
// result: (NeqB x y)
for {
for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
if v_0.Op != OpNot {
continue
}
x := v_0.Args[0]
y := v_1
v.reset(OpNeqB)
v.AddArg2(x, y)
return true
}
break
}
return false
}
func rewriteValuegeneric_OpEqInter(v *Value) bool {
@@ -19738,19 +19753,16 @@ func rewriteValuegeneric_OpNeqB(v *Value) bool {
}
break
}
// match: (NeqB (Not x) (Not y))
// result: (NeqB x y)
// match: (NeqB (Not x) y)
// result: (EqB x y)
for {
for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 {
if v_0.Op != OpNot {
continue
}
x := v_0.Args[0]
if v_1.Op != OpNot {
continue
}
y := v_1.Args[0]
v.reset(OpNeqB)
y := v_1
v.reset(OpEqB)
v.AddArg2(x, y)
return true
}