aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRémy Oudompheng <oudomphe@phare.normalesup.org>2013-05-30 08:32:00 +0200
committerRémy Oudompheng <oudomphe@phare.normalesup.org>2013-05-30 08:32:00 +0200
commit2c4b029b752a5aa8315e56b9563b2052fe8dd3fe (patch)
tree380cc04648636308ad62368b53c7129cf892e3af /src
parent0b88587d229d737a27f2dd0f8f75f5df41a11cf7 (diff)
downloadgo-2c4b029b752a5aa8315e56b9563b2052fe8dd3fe.tar.xz
cmd/gc: use escape analysis result for make([]T, constant
Escape analysis already gives that the underlying array does not escape but the result was ignored. Fixes #5484. R=golang-dev, dave, daniel.morsing CC=golang-dev https://golang.org/cl/9662046
Diffstat (limited to 'src')
-rw-r--r--src/cmd/gc/walk.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index 3dd8930969..a4e20e046c 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -1246,18 +1246,35 @@ walkexpr(Node **np, NodeList **init)
goto ret;
case OMAKESLICE:
- // makeslice(t *Type, nel int64, max int64) (ary []any)
l = n->left;
r = n->right;
if(r == nil)
l = r = safeexpr(l, init);
t = n->type;
- fn = syslook("makeslice", 1);
- argtype(fn, t->type); // any-1
- n = mkcall1(fn, n->type, init,
- typename(n->type),
- conv(l, types[TINT64]),
- conv(r, types[TINT64]));
+ if(n->esc == EscNone
+ && smallintconst(l) && smallintconst(r)
+ && mpgetfix(r->val.u.xval) < (1ULL<<16) / t->type->width) {
+ // var arr [r]T
+ // n = arr[:l]
+ t = aindex(r, t->type); // [r]T
+ var = temp(t);
+ a = nod(OAS, var, N); // zero temp
+ typecheck(&a, Etop);
+ *init = list(*init, a);
+ r = nod(OSLICE, var, nod(OKEY, N, l)); // arr[:l]
+ r = conv(r, n->type); // in case n->type is named.
+ typecheck(&r, Erv);
+ walkexpr(&r, init);
+ n = r;
+ } else {
+ // makeslice(t *Type, nel int64, max int64) (ary []any)
+ fn = syslook("makeslice", 1);
+ argtype(fn, t->type); // any-1
+ n = mkcall1(fn, n->type, init,
+ typename(n->type),
+ conv(l, types[TINT64]),
+ conv(r, types[TINT64]));
+ }
goto ret;
case ORUNESTR: