From: Cherry Zhang Date: Thu, 29 Sep 2016 13:22:01 +0000 (-0400) Subject: cmd/internal/obj/arm: optimize MOVW $-off(R), R X-Git-Tag: go1.8beta1~1119 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fedb0b30188952dc082672cbd45b39a49136d29c;p=gostls13.git cmd/internal/obj/arm: optimize MOVW $-off(R), R When offset < 0 and -offset fits in instruction, generate SUB instruction, instead of ADD with constant from the pool. Fixes #13280. Change-Id: I57d97fe9300fe1f6554365e2262393ef50acbdd3 Reviewed-on: https://go-review.googlesource.com/30014 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- diff --git a/src/cmd/internal/obj/arm/asm5.go b/src/cmd/internal/obj/arm/asm5.go index 70860231a3..c47863db47 100644 --- a/src/cmd/internal/obj/arm/asm5.go +++ b/src/cmd/internal/obj/arm/asm5.go @@ -1155,8 +1155,10 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { } func aconsize(ctxt *obj.Link) int { - t := int(immrot(uint32(ctxt.Instoffset))) - if t != 0 { + if t := int(immrot(uint32(ctxt.Instoffset))); t != 0 { + return C_RACON + } + if t := int(immrot(uint32(-ctxt.Instoffset))); t != 0 { return C_RACON } return C_LACON @@ -1537,11 +1539,15 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) { case 3: /* add R<<[IR],[R],R */ o1 = mov(ctxt, p) - case 4: /* add $I,[R],R */ + case 4: /* MOVW $off(R), R -> add $off,[R],R */ aclass(ctxt, &p.From) - - o1 = oprrr(ctxt, AADD, int(p.Scond)) - o1 |= uint32(immrot(uint32(ctxt.Instoffset))) + if ctxt.Instoffset < 0 { + o1 = oprrr(ctxt, ASUB, int(p.Scond)) + o1 |= uint32(immrot(uint32(-ctxt.Instoffset))) + } else { + o1 = oprrr(ctxt, AADD, int(p.Scond)) + o1 |= uint32(immrot(uint32(ctxt.Instoffset))) + } r := int(p.From.Reg) if r == 0 { r = int(o.param)