]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: support zero type for *T
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 13 Jul 2015 20:01:08 +0000 (14:01 -0600)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 13 Jul 2015 21:29:01 +0000 (21:29 +0000)
Change-Id: I4c9bcea01e2c4333c2a3592b66f1da9f424747a4
Reviewed-on: https://go-review.googlesource.com/12130
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go

index c4bfb2e731f1ba0794eb1925619aaf64d1442328..c75dd162649881e87b65da1dd5d0e203e5484f85 100644 (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?
index aa0f6a7943d72dca22653c467f22f47f2b42e08a..1eb29105d2f775e9a347821dfd9d551df4b25cde 100644 (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)
 
index d4447ea49a203c98045d90b66ed094ed28fd91d3..728c45cc49f5b4b715e4a37689a9386aaef61743 100644 (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