From: Michael Munday Date: Tue, 12 Apr 2016 14:27:16 +0000 (-0400) Subject: cmd/compile/internal/gc: minor Cgen_checknil cleanup X-Git-Tag: go1.7beta1~749 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7f5a063d157c777d8e78a567fc9538929bfd38f5;p=gostls13.git cmd/compile/internal/gc: minor Cgen_checknil cleanup Most architectures can only generate nil checks when the the address to check is in a register. Currently only amd64 and 386 can generate checks for addresses that reside in memory. This is unlikely to change so the architecture check has been inverted. Change-Id: I73697488a183406c79a9039c62823712b510bb6a Reviewed-on: https://go-review.googlesource.com/21861 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go index bfb65ade38..f6e9ab3b06 100644 --- a/src/cmd/compile/internal/gc/pgen.go +++ b/src/cmd/compile/internal/gc/pgen.go @@ -324,7 +324,12 @@ func Cgen_checknil(n *Node) { Fatalf("bad checknil") } - if (Thearch.LinkArch.InFamily(sys.MIPS64, sys.ARM, sys.ARM64, sys.PPC64) && n.Op != OREGISTER) || !n.Addable || n.Op == OLITERAL { + // Most architectures require that the address to be checked is + // in a register (it could be in memory). + needsReg := !Thearch.LinkArch.InFamily(sys.AMD64, sys.I386) + + // Move the address to be checked into a register if necessary. + if (needsReg && n.Op != OREGISTER) || !n.Addable || n.Op == OLITERAL { var reg Node Regalloc(®, Types[Tptr], n) Cgen(n, ®)