From ed0c5dd11f983d0e54806cd087ec852e43fa9f9e Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Sat, 6 Oct 2012 11:51:06 +1000 Subject: [PATCH] cmd/5g: avoid temporary during constant OINDEX func addr(s[]int) *int { return &s[2] } --- prog list "addr" --- 0000 (/home/dfc/src/addr.go:5) TEXT addr+0(SB),$0-16 0001 (/home/dfc/src/addr.go:6) MOVW $s+0(FP),R0 0002 (/home/dfc/src/addr.go:6) MOVW 4(R0),R1 0003 (/home/dfc/src/addr.go:6) MOVW $2,R2 0004 (/home/dfc/src/addr.go:6) CMP R2,R1, 0005 (/home/dfc/src/addr.go:6) BHI ,7(APC) 0006 (/home/dfc/src/addr.go:6) BL ,runtime.panicindex+0(SB) 0007 (/home/dfc/src/addr.go:6) MOVW 0(R0),R0 0008 (/home/dfc/src/addr.go:6) MOVW $8,R1 0009 (/home/dfc/src/addr.go:6) ADD R1,R0 0010 (/home/dfc/src/addr.go:6) MOVW R0,.noname+12(FP) 0011 (/home/dfc/src/addr.go:6) RET , becomes --- prog list "addr" --- 0000 (/home/dfc/src/addr.go:5) TEXT addr+0(SB),$0-16 0001 (/home/dfc/src/addr.go:6) MOVW $s+0(FP),R0 0002 (/home/dfc/src/addr.go:6) MOVW 4(R0),R1 0003 (/home/dfc/src/addr.go:6) MOVW $2,R2 0004 (/home/dfc/src/addr.go:6) CMP R2,R1, 0005 (/home/dfc/src/addr.go:6) BHI ,7(APC) 0006 (/home/dfc/src/addr.go:6) BL ,runtime.panicindex+0(SB) 0007 (/home/dfc/src/addr.go:6) MOVW 0(R0),R0 0008 (/home/dfc/src/addr.go:6) ADD $8,R0 0009 (/home/dfc/src/addr.go:6) MOVW R0,.noname+12(FP) 0010 (/home/dfc/src/addr.go:6) RET , R=rsc, remyoudompheng, minux.ma CC=golang-dev https://golang.org/cl/6590056 --- src/cmd/5g/cgen.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cmd/5g/cgen.c b/src/cmd/5g/cgen.c index eaa813fcf7..5065e0cd9b 100644 --- a/src/cmd/5g/cgen.c +++ b/src/cmd/5g/cgen.c @@ -733,11 +733,7 @@ agen(Node *n, Node *res) } nodconst(&n2, types[tptr], v*w); - regalloc(&n4, n2.type, N); - gmove(&n2, &n4); - gins(optoas(OADD, types[tptr]), &n4, &n3); - regfree(&n4); - + gins(optoas(OADD, types[tptr]), &n2, &n3); gmove(&n3, res); regfree(&n3); break;