From 37ab663ae5c6ecfea569c00b27ace7c38402088a Mon Sep 17 00:00:00 2001 From: Georg Schmid Date: Tue, 14 May 2019 11:17:09 +0200 Subject: [PATCH] Improve SameValue folding in TypedOptimization to ignore renames R=jarin@google.com, tebbi@google.com Change-Id: I23b92df275ce294d62c906a0b94dcb9b15f6be39 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1609803 Commit-Queue: Georg Schmid Reviewed-by: Tobias Tebbi Cr-Commit-Position: refs/heads/master@{#61472} --- src/compiler/backend/instruction-selector.cc | 2 +- src/compiler/js-intrinsic-lowering.cc | 5 ++-- src/compiler/js-intrinsic-lowering.h | 2 +- src/compiler/typed-optimization.cc | 25 ++++++++++++++++++- src/runtime/runtime-test.cc | 2 +- src/runtime/runtime.h | 2 +- .../compiler/constant-fold-add-static.js | 2 +- 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/compiler/backend/instruction-selector.cc b/src/compiler/backend/instruction-selector.cc index 97f91271e7..459f9a28fc 100644 --- a/src/compiler/backend/instruction-selector.cc +++ b/src/compiler/backend/instruction-selector.cc @@ -2842,7 +2842,7 @@ void InstructionSelector::VisitUnreachable(Node* node) { void InstructionSelector::VisitStaticAssert(Node* node) { node->InputAt(0)->Print(); - FATAL("Expected static assert to hold, but got non-true input!\n"); + FATAL("Expected turbofan static assert to hold, but got non-true input!\n"); } void InstructionSelector::VisitDeadValue(Node* node) { diff --git a/src/compiler/js-intrinsic-lowering.cc b/src/compiler/js-intrinsic-lowering.cc index f3b2b3170c..a143eda758 100644 --- a/src/compiler/js-intrinsic-lowering.cc +++ b/src/compiler/js-intrinsic-lowering.cc @@ -28,7 +28,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); const Runtime::Function* const f = Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); - if (f->function_id == Runtime::kStaticAssert) return ReduceStaticAssert(node); + if (f->function_id == Runtime::kTurbofanStaticAssert) + return ReduceTurbofanStaticAssert(node); if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); switch (f->function_id) { case Runtime::kInlineCopyDataProperties: @@ -269,7 +270,7 @@ Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { return Change(node, simplified()->ObjectIsSmi()); } -Reduction JSIntrinsicLowering::ReduceStaticAssert(Node* node) { +Reduction JSIntrinsicLowering::ReduceTurbofanStaticAssert(Node* node) { if (FLAG_always_opt) { // Ignore static asserts, as we most likely won't have enough information RelaxEffectsAndControls(node); diff --git a/src/compiler/js-intrinsic-lowering.h b/src/compiler/js-intrinsic-lowering.h index 36cc1213bf..2162a09d8c 100644 --- a/src/compiler/js-intrinsic-lowering.h +++ b/src/compiler/js-intrinsic-lowering.h @@ -58,7 +58,7 @@ class V8_EXPORT_PRIVATE JSIntrinsicLowering final Reduction ReduceIsInstanceType(Node* node, InstanceType instance_type); Reduction ReduceIsJSReceiver(Node* node); Reduction ReduceIsSmi(Node* node); - Reduction ReduceStaticAssert(Node* node); + Reduction ReduceTurbofanStaticAssert(Node* node); Reduction ReduceToLength(Node* node); Reduction ReduceToObject(Node* node); Reduction ReduceToString(Node* node); diff --git a/src/compiler/typed-optimization.cc b/src/compiler/typed-optimization.cc index a555d7f63b..556fec5d7e 100644 --- a/src/compiler/typed-optimization.cc +++ b/src/compiler/typed-optimization.cc @@ -113,6 +113,26 @@ base::Optional GetStableMapFromObjectType(JSHeapBroker* broker, return {}; } +Node* ResolveRenames(Node* node) { + while (true) { + switch (node->opcode()) { + case IrOpcode::kCheckHeapObject: + case IrOpcode::kCheckNumber: + case IrOpcode::kCheckSmi: + case IrOpcode::kFinishRegion: + case IrOpcode::kTypeGuard: + if (node->IsDead()) { + return node; + } else { + node = node->InputAt(0); + continue; + } + default: + return node; + } + } +} + } // namespace Reduction TypedOptimization::ReduceConvertReceiver(Node* node) { @@ -507,7 +527,10 @@ Reduction TypedOptimization::ReduceSameValue(Node* node) { Node* const rhs = NodeProperties::GetValueInput(node, 1); Type const lhs_type = NodeProperties::GetType(lhs); Type const rhs_type = NodeProperties::GetType(rhs); - if (lhs == rhs) { + if (ResolveRenames(lhs) == ResolveRenames(rhs)) { + if (NodeProperties::GetType(node).IsNone()) { + return NoChange(); + } // SameValue(x,x) => #true return Replace(jsgraph()->TrueConstant()); } else if (lhs_type.Is(Type::Unique()) && rhs_type.Is(Type::Unique())) { diff --git a/src/runtime/runtime-test.cc b/src/runtime/runtime-test.cc index b709f0c0b6..faff3d754c 100644 --- a/src/runtime/runtime-test.cc +++ b/src/runtime/runtime-test.cc @@ -1277,7 +1277,7 @@ RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) { return ReadOnlyRoots(isolate).undefined_value(); } -RUNTIME_FUNCTION(Runtime_StaticAssert) { +RUNTIME_FUNCTION(Runtime_TurbofanStaticAssert) { SealHandleScope shs(isolate); // Always lowered to StaticAssert node in Turbofan, so we should never get // here in compiled code. diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index aa21ff0f1a..f7c49822e3 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -519,7 +519,7 @@ namespace internal { F(WasmNumInterpretedCalls, 1, 1) \ F(WasmTraceMemory, 1, 1) \ F(SetWasmThreadsEnabled, 1, 1) \ - F(StaticAssert, 1, 1) \ + F(TurbofanStaticAssert, 1, 1) \ F(EnableCodeLoggingForTesting, 0, 1) #define FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \ diff --git a/test/mjsunit/compiler/constant-fold-add-static.js b/test/mjsunit/compiler/constant-fold-add-static.js index 5b148da28c..cdeb7f2ffc 100644 --- a/test/mjsunit/compiler/constant-fold-add-static.js +++ b/test/mjsunit/compiler/constant-fold-add-static.js @@ -7,7 +7,7 @@ // Check that constant-folding of arithmetic results in identical nodes. (function() { function foo(x) { - %StaticAssert(1 * x == x + 0); + %TurbofanStaticAssert(1 * x == x + 0); } foo(121); foo(122);