cmd/7g: change CHECKNIL sequence
We can use CBNZ instruction and make it one instruction shorter.
Saves 66kB in godoc.
Change-Id: Ie71fe7cf31e7f73644ee926f4f9624c009c3eb1a
Reviewed-on: https://go-review.googlesource.com/8634
Reviewed-by: Minux Ma <minux@golang.org>
diff --git a/src/cmd/7g/ggen.go b/src/cmd/7g/ggen.go
index c8f65a6..9b3ffce 100644
--- a/src/cmd/7g/ggen.go
+++ b/src/cmd/7g/ggen.go
@@ -483,7 +483,6 @@
// Expand CHECKNIL pseudo-op into actual nil pointer check.
func expandchecks(firstp *obj.Prog) {
var p1 *obj.Prog
- var p2 *obj.Prog
for p := (*obj.Prog)(firstp); p != nil; p = p.Link {
if gc.Debug_checknil != 0 && gc.Ctxt.Debugvlog != 0 {
@@ -500,38 +499,26 @@
}
// check is
- // CMP arg, ZR
- // BNE 2(PC) [likely]
+ // CBNZ arg, 2(PC)
// MOVD ZR, 0(arg)
p1 = gc.Ctxt.NewProg()
-
- p2 = gc.Ctxt.NewProg()
gc.Clearp(p1)
- gc.Clearp(p2)
- p1.Link = p2
- p2.Link = p.Link
+ p1.Link = p.Link
p.Link = p1
p1.Lineno = p.Lineno
- p2.Lineno = p.Lineno
p1.Pc = 9999
- p2.Pc = 9999
- p.As = arm64.ACMP
- p.Reg = arm64.REGZERO
- p1.As = arm64.ABNE
- //p1->from.type = TYPE_CONST;
- //p1->from.offset = 1; // likely
- p1.To.Type = obj.TYPE_BRANCH
-
- p1.To.Val = p2.Link
+ p.As = arm64.ACBNZ
+ p.To.Type = obj.TYPE_BRANCH
+ p.To.Val = p1.Link
// crash by write to memory address 0.
- p2.As = arm64.AMOVD
- p2.From.Type = obj.TYPE_REG
- p2.From.Reg = arm64.REGZERO
- p2.To.Type = obj.TYPE_MEM
- p2.To.Reg = p.From.Reg
- p2.To.Offset = 0
+ p1.As = arm64.AMOVD
+ p1.From.Type = obj.TYPE_REG
+ p1.From.Reg = arm64.REGZERO
+ p1.To.Type = obj.TYPE_MEM
+ p1.To.Reg = p.From.Reg
+ p1.To.Offset = 0
}
}
diff --git a/src/cmd/7g/prog.go b/src/cmd/7g/prog.go
index 733c405fa..023f302 100644
--- a/src/cmd/7g/prog.go
+++ b/src/cmd/7g/prog.go
@@ -122,6 +122,8 @@
arm64.ABLS: {gc.Cjmp, 0, 0, 0},
arm64.ABHI: {gc.Cjmp, 0, 0, 0},
arm64.ABHS: {gc.Cjmp, 0, 0, 0},
+ arm64.ACBZ: {gc.Cjmp, 0, 0, 0},
+ arm64.ACBNZ: {gc.Cjmp, 0, 0, 0},
obj.ARET: {gc.Break, 0, 0, 0},
obj.ADUFFZERO: {gc.Call, 0, 0, 0},
obj.ADUFFCOPY: {gc.Call, 0, 0, 0},