Commit 8f9cf552 authored by Keith Randall's avatar Keith Randall Committed by Brad Fitzpatrick

cmd/compile: constant fold !true and !false

Constant fold Not of boolean constants.

Noticed while working on #23504.

Change-Id: I965705154ee7348a1a159fad4e029b922d3171b3
Reviewed-on: https://go-review.googlesource.com/88956
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMartin Möhrmann <moehrmann@google.com>
parent d1f679a6
...@@ -150,6 +150,8 @@ ...@@ -150,6 +150,8 @@
(Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [f2i(float64(i2f32(c) / i2f32(d)))]) (Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [f2i(float64(i2f32(c) / i2f32(d)))])
(Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) / i2f(d))]) (Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) / i2f(d))])
(Not (ConstBool [c])) -> (ConstBool [1-c])
// Convert x * 1 to x. // Convert x * 1 to x.
(Mul8 (Const8 [1]) x) -> x (Mul8 (Const8 [1]) x) -> x
(Mul16 (Const16 [1]) x) -> x (Mul16 (Const16 [1]) x) -> x
......
...@@ -17715,6 +17715,19 @@ func rewriteValuegeneric_OpNilCheck_0(v *Value) bool { ...@@ -17715,6 +17715,19 @@ func rewriteValuegeneric_OpNilCheck_0(v *Value) bool {
return false return false
} }
func rewriteValuegeneric_OpNot_0(v *Value) bool { func rewriteValuegeneric_OpNot_0(v *Value) bool {
// match: (Not (ConstBool [c]))
// cond:
// result: (ConstBool [1-c])
for {
v_0 := v.Args[0]
if v_0.Op != OpConstBool {
break
}
c := v_0.AuxInt
v.reset(OpConstBool)
v.AuxInt = 1 - c
return true
}
// match: (Not (Eq64 x y)) // match: (Not (Eq64 x y))
// cond: // cond:
// result: (Neq64 x y) // result: (Neq64 x y)
...@@ -17859,6 +17872,9 @@ func rewriteValuegeneric_OpNot_0(v *Value) bool { ...@@ -17859,6 +17872,9 @@ func rewriteValuegeneric_OpNot_0(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_10(v *Value) bool {
// match: (Not (NeqB x y)) // match: (Not (NeqB x y))
// cond: // cond:
// result: (EqB x y) // result: (EqB x y)
...@@ -17875,9 +17891,6 @@ func rewriteValuegeneric_OpNot_0(v *Value) bool { ...@@ -17875,9 +17891,6 @@ func rewriteValuegeneric_OpNot_0(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_10(v *Value) bool {
// match: (Not (Greater64 x y)) // match: (Not (Greater64 x y))
// cond: // cond:
// result: (Leq64 x y) // result: (Leq64 x y)
...@@ -18022,6 +18035,9 @@ func rewriteValuegeneric_OpNot_10(v *Value) bool { ...@@ -18022,6 +18035,9 @@ func rewriteValuegeneric_OpNot_10(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_20(v *Value) bool {
// match: (Not (Geq32 x y)) // match: (Not (Geq32 x y))
// cond: // cond:
// result: (Less32 x y) // result: (Less32 x y)
...@@ -18038,9 +18054,6 @@ func rewriteValuegeneric_OpNot_10(v *Value) bool { ...@@ -18038,9 +18054,6 @@ func rewriteValuegeneric_OpNot_10(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_20(v *Value) bool {
// match: (Not (Geq16 x y)) // match: (Not (Geq16 x y))
// cond: // cond:
// result: (Less16 x y) // result: (Less16 x y)
...@@ -18185,6 +18198,9 @@ func rewriteValuegeneric_OpNot_20(v *Value) bool { ...@@ -18185,6 +18198,9 @@ func rewriteValuegeneric_OpNot_20(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_30(v *Value) bool {
// match: (Not (Less8 x y)) // match: (Not (Less8 x y))
// cond: // cond:
// result: (Geq8 x y) // result: (Geq8 x y)
...@@ -18201,9 +18217,6 @@ func rewriteValuegeneric_OpNot_20(v *Value) bool { ...@@ -18201,9 +18217,6 @@ func rewriteValuegeneric_OpNot_20(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_30(v *Value) bool {
// match: (Not (Less64U x y)) // match: (Not (Less64U x y))
// cond: // cond:
// result: (Geq64U x y) // result: (Geq64U x y)
...@@ -18348,6 +18361,9 @@ func rewriteValuegeneric_OpNot_30(v *Value) bool { ...@@ -18348,6 +18361,9 @@ func rewriteValuegeneric_OpNot_30(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_40(v *Value) bool {
// match: (Not (Leq32U x y)) // match: (Not (Leq32U x y))
// cond: // cond:
// result: (Greater32U x y) // result: (Greater32U x y)
...@@ -18364,9 +18380,6 @@ func rewriteValuegeneric_OpNot_30(v *Value) bool { ...@@ -18364,9 +18380,6 @@ func rewriteValuegeneric_OpNot_30(v *Value) bool {
v.AddArg(y) v.AddArg(y)
return true return true
} }
return false
}
func rewriteValuegeneric_OpNot_40(v *Value) bool {
// match: (Not (Leq16U x y)) // match: (Not (Leq16U x y))
// cond: // cond:
// result: (Greater16U x y) // result: (Greater16U x y)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment