From 3dcc63f750c425fcb9ce2ec66812489881dafeee Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Sat, 22 Dec 2012 09:09:31 +1100 Subject: [PATCH] cmd/5g: avoid temporaries in agen OINDEX Most benchmarks are within the 3% margin of error. This code path is quite common in the fmt package. linux/arm, Freescale iMX.53 (cortex-a8) fmt: benchmark old ns/op new ns/op delta BenchmarkSprintfEmpty 925 785 -15.14% BenchmarkSprintfString 5050 5039 -0.22% BenchmarkSprintfInt 4425 4406 -0.43% BenchmarkSprintfIntInt 5802 5762 -0.69% BenchmarkSprintfPrefixedInt 7029 6541 -6.94% BenchmarkSprintfFloat 10278 10083 -1.90% BenchmarkManyArgs 18558 17606 -5.13% BenchmarkScanInts 15592690 15415360 -1.14% BenchmarkScanRecursiveInt 25155020 25050900 -0.41% R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6921056 --- src/cmd/5g/cgen.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cmd/5g/cgen.c b/src/cmd/5g/cgen.c index 9325741059..e6c92f68f6 100644 --- a/src/cmd/5g/cgen.c +++ b/src/cmd/5g/cgen.c @@ -1007,22 +1007,21 @@ agenr(Node *n, Node *a, Node *res) if(!debug['B'] && !n->bounded) { // check bounds - regalloc(&n4, types[TUINT32], N); if(isconst(nl, CTSTR)) { - nodconst(&n1, types[TUINT32], nl->val.u.sval->len); - gmove(&n1, &n4); + nodconst(&n4, types[TUINT32], nl->val.u.sval->len); } else if(isslice(nl->type) || nl->type->etype == TSTRING) { n1 = n3; n1.op = OINDREG; n1.type = types[tptr]; n1.xoffset = Array_nel; + regalloc(&n4, types[TUINT32], N); gmove(&n1, &n4); } else { - nodconst(&n1, types[TUINT32], nl->type->bound); - gmove(&n1, &n4); + nodconst(&n4, types[TUINT32], nl->type->bound); } gcmp(optoas(OCMP, types[TUINT32]), &n2, &n4); - regfree(&n4); + if(n4.op == OREGISTER) + regfree(&n4); p1 = gbranch(optoas(OLT, types[TUINT32]), T, +1); if(p2) patch(p2, pc); -- 2.48.1