v8/test/mjsunit/compiler/native-context-specialization-string-concat.js
Ross McIlroy d8d8f8b316 [TurboFan] Add constant folding for StringConcat to NativeContextSpecialization.
Adds constant folding for the StringConcat bytecode to
NativeContextSpecialization. Can reduce operator to either a fully folded
constant string, or a JSAdd or a StringConcat with a reduced number of
operators.

BUG=v8:6243, chromium:738312

Change-Id: I6b2be6a3d95230a23f3c7390a4f7be5181c49a2a
Reviewed-on: https://chromium-review.googlesource.com/559146
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46461}
2017-07-06 22:37:32 +00:00

38 lines
834 B
JavaScript

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
var foo = 'foo';
var bar = 'bar';
var a;
var b;
var c;
var d;
function baz() { return 'baz'; }
function test(arg) {
// All operands are constant folded by native context
// specialization / inlining.
a = '"' + foo + '-' + bar + '"';
b = '"' + foo + '-' + baz() + '"';
// Reduce down to a JSAdd of folded constant + arg.
c = foo + bar + arg;
// Reduces to a StringConcat with three operands.
d = '"' + foo + arg + bar + '"';
}
test('boo');
%OptimizeFunctionOnNextCall(test);
test('baa');
assertEquals('"foo-bar"', a);
assertEquals('"foo-baz"', b);
assertEquals('foobarbaa', c);
assertEquals('"foobaabar"', d);