1
0
mirror of https://github.com/golang/go synced 2024-10-01 13:18:33 -06:00

cmd/compile: simplify IsNonNil ConstNil

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>
This commit is contained in:
Cherry Zhang 2017-01-20 12:14:22 -05:00
parent fddc004537
commit 6ad2d6aa92
2 changed files with 20 additions and 0 deletions

View File

@ -650,6 +650,7 @@
(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,

View 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