From 905e8dfa27b943aa306cadb1a6880bbeb4051173 Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Mon, 8 Oct 2012 09:51:04 +1100 Subject: [PATCH] cmd/5g: avoid temporaries during gcmp(reg, constant) Address several instances of unneeded temporaries when using gcmp. func M(m map[int]bool) int { return len(m) } --- prog list "M" --- 0000 (/home/dfc/src/map.go:3) TEXT M+0(SB),$0-8 0001 (/home/dfc/src/map.go:4) MOVW m+0(FP),R0 0002 (/home/dfc/src/map.go:4) MOVW $0,R1 0003 (/home/dfc/src/map.go:4) CMP R1,R0, 0004 (/home/dfc/src/map.go:4) BEQ ,6(APC) 0005 (/home/dfc/src/map.go:4) MOVW 0(R0),R0 0006 (/home/dfc/src/map.go:4) MOVW R0,.noname+4(FP) 0007 (/home/dfc/src/map.go:4) RET , after: --- prog list "M" --- 0000 (/home/dfc/src/map.go:3) TEXT M+0(SB),$0-8 0001 (/home/dfc/src/map.go:4) MOVW m+0(FP),R0 0002 (/home/dfc/src/map.go:4) CMP $0,R0, 0003 (/home/dfc/src/map.go:4) BEQ ,5(APC) 0004 (/home/dfc/src/map.go:4) MOVW 0(R0),R0 0005 (/home/dfc/src/map.go:4) MOVW R0,.noname+4(FP) 0006 (/home/dfc/src/map.go:4) RET , func C(c chan int) int { return cap(c) } --- prog list "C" --- 0000 (/home/dfc/src/map.go:3) TEXT C+0(SB),$0-8 0001 (/home/dfc/src/map.go:4) MOVW c+0(FP),R0 0002 (/home/dfc/src/map.go:4) MOVW $0,R1 0003 (/home/dfc/src/map.go:4) CMP R1,R0, 0004 (/home/dfc/src/map.go:4) BEQ ,6(APC) 0005 (/home/dfc/src/map.go:4) MOVW 4(R0),R0 0006 (/home/dfc/src/map.go:4) MOVW R0,.noname+4(FP) 0007 (/home/dfc/src/map.go:4) RET , after: --- prog list "C" --- 0000 (/home/dfc/src/map.go:3) TEXT C+0(SB),$0-8 0001 (/home/dfc/src/map.go:4) MOVW c+0(FP),R0 0002 (/home/dfc/src/map.go:4) CMP $0,R0, 0003 (/home/dfc/src/map.go:4) BEQ ,5(APC) 0004 (/home/dfc/src/map.go:4) MOVW 4(R0),R0 0005 (/home/dfc/src/map.go:4) MOVW R0,.noname+4(FP) 0006 (/home/dfc/src/map.go:4) RET , R=rsc, minux.ma, remyoudompheng CC=golang-dev https://golang.org/cl/6618054 --- src/cmd/5g/cgen.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/cmd/5g/cgen.c b/src/cmd/5g/cgen.c index 7a2f5e5ab9e..7db5e213463 100644 --- a/src/cmd/5g/cgen.c +++ b/src/cmd/5g/cgen.c @@ -328,10 +328,7 @@ cgen(Node *n, Node *res) cgen(nl, &n1); nodconst(&n2, types[tptr], 0); - regalloc(&n3, n2.type, N); - gmove(&n2, &n3); - gcmp(optoas(OCMP, types[tptr]), &n1, &n3); - regfree(&n3); + gcmp(optoas(OCMP, types[tptr]), &n1, &n2); p1 = gbranch(optoas(OEQ, types[tptr]), T, -1); n2 = n1; @@ -370,10 +367,7 @@ cgen(Node *n, Node *res) cgen(nl, &n1); nodconst(&n2, types[tptr], 0); - regalloc(&n3, n2.type, N); - gmove(&n2, &n3); - gcmp(optoas(OCMP, types[tptr]), &n1, &n3); - regfree(&n3); + gcmp(optoas(OCMP, types[tptr]), &n1, &n2); p1 = gbranch(optoas(OEQ, types[tptr]), T, -1); n2 = n1;