]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/5g: avoid temporaries in agen OINDEX
authorDave Cheney <dave@cheney.net>
Fri, 21 Dec 2012 22:09:31 +0000 (09:09 +1100)
committerDave Cheney <dave@cheney.net>
Fri, 21 Dec 2012 22:09:31 +0000 (09:09 +1100)
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

index 93257410591cf3f2ba799b0181337deb2daf928f..e6c92f68f6e4aee04128e6231bd0c95e6400728e 100644 (file)
@@ -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);