From: Dave Cheney Date: Fri, 21 Dec 2012 22:09:31 +0000 (+1100) Subject: cmd/5g: avoid temporaries in agen OINDEX X-Git-Tag: go1.1rc2~1566 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3dcc63f750c425fcb9ce2ec66812489881dafeee;p=gostls13.git 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 --- 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);