]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify IsNonNil ConstNil
authorCherry Zhang <cherryyz@google.com>
Fri, 20 Jan 2017 17:14:22 +0000 (12:14 -0500)
committerCherry Zhang <cherryyz@google.com>
Thu, 2 Feb 2017 21:28:50 +0000 (21:28 +0000)
Change-Id: I9ed5a2065cef06708e319b16c801da2eff42004e
Reviewed-on: https://go-review.googlesource.com/35497
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 99f8d0a984e02102446dcf8bca5687ea99ea4fe0..7891d42d8ad1494ef9c74b788e98f59884934ca8 100644 (file)
 (NeqPtr (ConstNil) p) -> (IsNonNil p)
 (EqPtr p (ConstNil)) -> (Not (IsNonNil p))
 (EqPtr (ConstNil) p) -> (Not (IsNonNil p))
+(IsNonNil (ConstNil)) -> (ConstBool [0])
 
 // slice and interface comparisons
 // The frontend ensures that we can only compare against nil,
index 0fde363b3eefeae160436528823c6b3aae7ac31c..9fcffce0c71cdba2df3943a220a006ab3450f6be 100644 (file)
@@ -114,6 +114,8 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
                return rewriteValuegeneric_OpIMake(v, config)
        case OpIsInBounds:
                return rewriteValuegeneric_OpIsInBounds(v, config)
+       case OpIsNonNil:
+               return rewriteValuegeneric_OpIsNonNil(v, config)
        case OpIsSliceInBounds:
                return rewriteValuegeneric_OpIsSliceInBounds(v, config)
        case OpLeq16:
@@ -3407,6 +3409,23 @@ func rewriteValuegeneric_OpIsInBounds(v *Value, config *Config) bool {
        }
        return false
 }
+func rewriteValuegeneric_OpIsNonNil(v *Value, config *Config) bool {
+       b := v.Block
+       _ = b
+       // match: (IsNonNil (ConstNil))
+       // cond:
+       // result: (ConstBool [0])
+       for {
+               v_0 := v.Args[0]
+               if v_0.Op != OpConstNil {
+                       break
+               }
+               v.reset(OpConstBool)
+               v.AuxInt = 0
+               return true
+       }
+       return false
+}
 func rewriteValuegeneric_OpIsSliceInBounds(v *Value, config *Config) bool {
        b := v.Block
        _ = b