[dev.ssa] cmd/compile: support zero type for *T

Change-Id: I4c9bcea01e2c4333c2a3592b66f1da9f424747a4
Reviewed-on: https://go-review.googlesource.com/12130
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Brad Fitzpatrick 2015-07-13 14:01:08 -06:00
parent 50e59bb9c8
commit a92bd66282
3 changed files with 20 additions and 1 deletions

View file

@ -652,7 +652,7 @@ func (s *state) assign(op uint8, left *Node, right *Node) {
switch {
case t.IsString():
val = s.entryNewValue0A(ssa.OpConst, left.Type, "")
case t.IsInteger():
case t.IsInteger() || t.IsPtr():
val = s.entryNewValue0(ssa.OpConst, left.Type)
case t.IsBoolean():
val = s.entryNewValue0A(ssa.OpConst, left.Type, false) // TODO: store bools as 0/1 in AuxInt?

View file

@ -76,6 +76,7 @@
(OffPtr [off] ptr) -> (ADDQconst [off] ptr)
(Const <t> [val]) && t.IsInteger() -> (MOVQconst [val])
(Const <t>) && t.IsPtr() -> (MOVQconst [0]) // nil is the only const pointer
(Addr {sym} base) -> (LEAQ {sym} base)

View file

@ -499,6 +499,24 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto end4c8bfe9df26fc5aa2bd76b211792732a
end4c8bfe9df26fc5aa2bd76b211792732a:
;
// match: (Const <t>)
// cond: t.IsPtr()
// result: (MOVQconst [0])
{
t := v.Type
if !(t.IsPtr()) {
goto endd23abe8d7061f11c260b162e24eec060
}
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto endd23abe8d7061f11c260b162e24eec060
endd23abe8d7061f11c260b162e24eec060:
;
case OpConvNop:
// match: (ConvNop <t> x)
// cond: t == x.Type