]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: constant fold !true and !false
authorKeith Randall <khr@google.com>
Mon, 22 Jan 2018 18:06:10 +0000 (10:06 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 14 Feb 2018 20:28:08 +0000 (20:28 +0000)
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: Martin Möhrmann <moehrmann@google.com>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 9b004be9f1215e95a8e57458a7f973dee907ecb8..b65adba17633808a170cd5a546e0b4831b75e3b2 100644 (file)
 (Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [f2i(float64(i2f32(c) / i2f32(d)))])
 (Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) / i2f(d))])
 
+(Not (ConstBool [c])) -> (ConstBool [1-c])
+
 // Convert x * 1 to x.
 (Mul8  (Const8  [1]) x) -> x
 (Mul16 (Const16 [1]) x) -> x
index def2cca9fcd1599f08b85cbb5d51b796cfc71346..0ef79b0ed6b26bd1d682d6da0ef37ad7c2cb5be6 100644 (file)
@@ -17715,6 +17715,19 @@ func rewriteValuegeneric_OpNilCheck_0(v *Value) bool {
        return false
 }
 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))
        // cond:
        // result: (Neq64 x y)
@@ -17859,6 +17872,9 @@ func rewriteValuegeneric_OpNot_0(v *Value) bool {
                v.AddArg(y)
                return true
        }
+       return false
+}
+func rewriteValuegeneric_OpNot_10(v *Value) bool {
        // match: (Not (NeqB x y))
        // cond:
        // result: (EqB  x y)
@@ -17875,9 +17891,6 @@ func rewriteValuegeneric_OpNot_0(v *Value) bool {
                v.AddArg(y)
                return true
        }
-       return false
-}
-func rewriteValuegeneric_OpNot_10(v *Value) bool {
        // match: (Not (Greater64 x y))
        // cond:
        // result: (Leq64 x y)
@@ -18022,6 +18035,9 @@ func rewriteValuegeneric_OpNot_10(v *Value) bool {
                v.AddArg(y)
                return true
        }
+       return false
+}
+func rewriteValuegeneric_OpNot_20(v *Value) bool {
        // match: (Not (Geq32 x y))
        // cond:
        // result: (Less32 x y)
@@ -18038,9 +18054,6 @@ func rewriteValuegeneric_OpNot_10(v *Value) bool {
                v.AddArg(y)
                return true
        }
-       return false
-}
-func rewriteValuegeneric_OpNot_20(v *Value) bool {
        // match: (Not (Geq16 x y))
        // cond:
        // result: (Less16 x y)
@@ -18185,6 +18198,9 @@ func rewriteValuegeneric_OpNot_20(v *Value) bool {
                v.AddArg(y)
                return true
        }
+       return false
+}
+func rewriteValuegeneric_OpNot_30(v *Value) bool {
        // match: (Not (Less8 x y))
        // cond:
        // result: (Geq8  x y)
@@ -18201,9 +18217,6 @@ func rewriteValuegeneric_OpNot_20(v *Value) bool {
                v.AddArg(y)
                return true
        }
-       return false
-}
-func rewriteValuegeneric_OpNot_30(v *Value) bool {
        // match: (Not (Less64U x y))
        // cond:
        // result: (Geq64U x y)
@@ -18348,6 +18361,9 @@ func rewriteValuegeneric_OpNot_30(v *Value) bool {
                v.AddArg(y)
                return true
        }
+       return false
+}
+func rewriteValuegeneric_OpNot_40(v *Value) bool {
        // match: (Not (Leq32U x y))
        // cond:
        // result: (Greater32U x y)
@@ -18364,9 +18380,6 @@ func rewriteValuegeneric_OpNot_30(v *Value) bool {
                v.AddArg(y)
                return true
        }
-       return false
-}
-func rewriteValuegeneric_OpNot_40(v *Value) bool {
        // match: (Not (Leq16U x y))
        // cond:
        // result: (Greater16U x y)