Skip to content

Commit fedb0b3

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 26531b3 commit fedb0b3

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/cmd/internal/obj/arm/asm5.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,10 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
11551155
}
11561156

11571157
func aconsize(ctxt *obj.Link) int {
1158-
t := int(immrot(uint32(ctxt.Instoffset)))
1159-
if t != 0 {
1158+
if t := int(immrot(uint32(ctxt.Instoffset))); t != 0 {
1159+
return C_RACON
1160+
}
1161+
if t := int(immrot(uint32(-ctxt.Instoffset))); t != 0 {
11601162
return C_RACON
11611163
}
11621164
return C_LACON
@@ -1537,11 +1539,15 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
15371539
case 3: /* add R<<[IR],[R],R */
15381540
o1 = mov(ctxt, p)
15391541

1540-
case 4: /* add $I,[R],R */
1542+
case 4: /* MOVW $off(R), R -> add $off,[R],R */
15411543
aclass(ctxt, &p.From)
1542-
1543-
o1 = oprrr(ctxt, AADD, int(p.Scond))
1544-
o1 |= uint32(immrot(uint32(ctxt.Instoffset)))
1544+
if ctxt.Instoffset < 0 {
1545+
o1 = oprrr(ctxt, ASUB, int(p.Scond))
1546+
o1 |= uint32(immrot(uint32(-ctxt.Instoffset)))
1547+
} else {
1548+
o1 = oprrr(ctxt, AADD, int(p.Scond))
1549+
o1 |= uint32(immrot(uint32(ctxt.Instoffset)))
1550+
}
15451551
r := int(p.From.Reg)
15461552
if r == 0 {
15471553
r = int(o.param)

0 commit comments

Comments
 (0)