Commit 6ad2d6aa authored by Cherry Zhang's avatar Cherry Zhang

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: 's avatarKeith Randall <khr@golang.org>
parent fddc0045
......@@ -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,
......
......@@ -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
......
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