Skip to content

Commit 8f9cf55

Browse files
randall77bradfitz
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Martin Möhrmann <[email protected]>
1 parent d1f679a commit 8f9cf55

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/cmd/compile/internal/ssa/gen/generic.rules

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
(Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [f2i(float64(i2f32(c) / i2f32(d)))])
151151
(Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) / i2f(d))])
152152

153+
(Not (ConstBool [c])) -> (ConstBool [1-c])
154+
153155
// Convert x * 1 to x.
154156
(Mul8 (Const8 [1]) x) -> x
155157
(Mul16 (Const16 [1]) x) -> x

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 25 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)