[turbofan] Eliminate empty string addition.
For additions like a+'' or ''+a where we have String feedback on the JSAdd, we can drop the concatenation and just check that a is a valid String already (via CheckString). BUG=v8:6259 R=petermarshall@chromium.org Review-Url: https://codereview.chromium.org/2894563002 Cr-Commit-Position: refs/heads/master@{#45395}
This commit is contained in:
parent
de4a4095cf
commit
cd1325a890
@ -488,13 +488,13 @@ JSTypedLowering::JSTypedLowering(Editor* editor,
|
||||
dependencies_(dependencies),
|
||||
flags_(flags),
|
||||
jsgraph_(jsgraph),
|
||||
pointer_comparable_type_(Type::Union(
|
||||
Type::Oddball(),
|
||||
Type::Union(
|
||||
Type::SymbolOrReceiver(),
|
||||
Type::HeapConstant(factory()->empty_string(), graph()->zone()),
|
||||
graph()->zone()),
|
||||
graph()->zone())),
|
||||
empty_string_type_(
|
||||
Type::HeapConstant(factory()->empty_string(), graph()->zone())),
|
||||
pointer_comparable_type_(
|
||||
Type::Union(Type::Oddball(),
|
||||
Type::Union(Type::SymbolOrReceiver(), empty_string_type_,
|
||||
graph()->zone()),
|
||||
graph()->zone())),
|
||||
type_cache_(TypeCache::Get()) {
|
||||
for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) {
|
||||
double min = kMinInt / (1 << k);
|
||||
@ -535,6 +535,23 @@ Reduction JSTypedLowering::ReduceJSAdd(Node* node) {
|
||||
if (r.ShouldCreateConsString()) {
|
||||
return ReduceCreateConsString(node);
|
||||
}
|
||||
// Eliminate useless concatenation of empty string.
|
||||
if ((flags() & kDeoptimizationEnabled) &&
|
||||
BinaryOperationHintOf(node->op()) == BinaryOperationHint::kString) {
|
||||
Node* effect = NodeProperties::GetEffectInput(node);
|
||||
Node* control = NodeProperties::GetControlInput(node);
|
||||
if (r.LeftInputIs(empty_string_type_)) {
|
||||
Node* value = effect = graph()->NewNode(simplified()->CheckString(),
|
||||
r.right(), effect, control);
|
||||
ReplaceWithValue(node, value, effect, control);
|
||||
return Replace(value);
|
||||
} else if (r.RightInputIs(empty_string_type_)) {
|
||||
Node* value = effect = graph()->NewNode(simplified()->CheckString(),
|
||||
r.left(), effect, control);
|
||||
ReplaceWithValue(node, value, effect, control);
|
||||
return Replace(value);
|
||||
}
|
||||
}
|
||||
StringAddFlags flags = STRING_ADD_CHECK_NONE;
|
||||
if (!r.LeftInputIs(Type::String())) {
|
||||
flags = STRING_ADD_CONVERT_LEFT;
|
||||
|
@ -105,6 +105,7 @@ class V8_EXPORT_PRIVATE JSTypedLowering final
|
||||
CompilationDependencies* dependencies_;
|
||||
Flags flags_;
|
||||
JSGraph* jsgraph_;
|
||||
Type* empty_string_type_;
|
||||
Type* shifted_int32_ranges_[4];
|
||||
Type* pointer_comparable_type_;
|
||||
TypeCache const& type_cache_;
|
||||
|
Loading…
Reference in New Issue
Block a user