]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/arm64: optimize constant pool
authorBen Shi <powerman1st@163.com>
Mon, 9 Apr 2018 11:12:15 +0000 (11:12 +0000)
committerCherry Zhang <cherryyz@google.com>
Thu, 12 Apr 2018 19:48:44 +0000 (19:48 +0000)
"MOVD $0xaaaaaaaa, R2"
"MOVD $-0x55555555, R3"

For the above instructions, 64-bit constants 0x00000000 aaaaaaaa
and 0xffffffff aaaaaaab are stored in the constant pool.

This CL optimizes them to
"MOVWU $0xaaaaaaaa, R2"
"MOVW $-0x05555555, R3"
and 32-bit constants 0xaaaaaaaa and 0xaaaaaaab are stored in the
constant pool.

There is a little size reduction (about total 5KB) in both the go
executable and the library files.

Change-Id: I7c4bfa6cd9c07da99c69a8f9c15010a0cce3b735
Reviewed-on: https://go-review.googlesource.com/105775
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/obj/arm64/asm7.go

index def589faf4f05a629c36cdefa9d24f985208f9a6..043a16c45af767313c47f2c90f23d85d883625a3 100644 (file)
@@ -933,6 +933,11 @@ func (c *ctxt7) flushpool(p *obj.Prog, skip int) {
 }
 
 /*
+ * MOVD foo(SB), R is actually
+ *   MOVD addr, REGTMP
+ *   MOVD REGTMP, R
+ * where addr is the address of the DWORD containing the address of foo.
+ *
  * TODO: hash
  */
 func (c *ctxt7) addpool(p *obj.Prog, a *obj.Addr) {
@@ -942,11 +947,17 @@ func (c *ctxt7) addpool(p *obj.Prog, a *obj.Addr) {
        t.As = AWORD
        sz := 4
 
-       // MOVD foo(SB), R is actually
-       //      MOVD addr, REGTMP
-       //      MOVD REGTMP, R
-       // where addr is the address of the DWORD containing the address of foo.
-       if p.As == AMOVD && a.Type != obj.TYPE_MEM || cls == C_ADDR || cls == C_VCON || lit != int64(int32(lit)) || uint64(lit) != uint64(uint32(lit)) {
+       if p.As == AMOVD && a.Type == obj.TYPE_CONST {
+               // simplify MOVD to MOVW/MOVWU to reduce constant pool size
+               if lit == int64(int32(lit)) { // -0x80000000 ~ 0x7fffffff
+                       p.As = AMOVW
+               } else if uint64(lit) == uint64(uint32(lit)) { // 0 ~ 0xffffffff
+                       p.As = AMOVWU
+               } else { // 64-bit
+                       t.As = ADWORD
+                       sz = 8
+               }
+       } else if p.As == AMOVD && a.Type != obj.TYPE_MEM || cls == C_ADDR || cls == C_VCON || lit != int64(int32(lit)) || uint64(lit) != uint64(uint32(lit)) {
                // conservative: don't know if we want signed or unsigned extension.
                // in case of ambiguity, store 64-bit
                t.As = ADWORD