Commit 37ab663a authored by Georg Schmid's avatar Georg Schmid Committed by Commit Bot

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 <gsps@google.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61472}
parent eb04aaab
...@@ -2842,7 +2842,7 @@ void InstructionSelector::VisitUnreachable(Node* node) { ...@@ -2842,7 +2842,7 @@ void InstructionSelector::VisitUnreachable(Node* node) {
void InstructionSelector::VisitStaticAssert(Node* node) { void InstructionSelector::VisitStaticAssert(Node* node) {
node->InputAt(0)->Print(); 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) { void InstructionSelector::VisitDeadValue(Node* node) {
......
...@@ -28,7 +28,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { ...@@ -28,7 +28,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) {
if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange();
const Runtime::Function* const f = const Runtime::Function* const f =
Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); 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(); if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange();
switch (f->function_id) { switch (f->function_id) {
case Runtime::kInlineCopyDataProperties: case Runtime::kInlineCopyDataProperties:
...@@ -269,7 +270,7 @@ Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) { ...@@ -269,7 +270,7 @@ Reduction JSIntrinsicLowering::ReduceIsSmi(Node* node) {
return Change(node, simplified()->ObjectIsSmi()); return Change(node, simplified()->ObjectIsSmi());
} }
Reduction JSIntrinsicLowering::ReduceStaticAssert(Node* node) { Reduction JSIntrinsicLowering::ReduceTurbofanStaticAssert(Node* node) {
if (FLAG_always_opt) { if (FLAG_always_opt) {
// Ignore static asserts, as we most likely won't have enough information // Ignore static asserts, as we most likely won't have enough information
RelaxEffectsAndControls(node); RelaxEffectsAndControls(node);
......
...@@ -58,7 +58,7 @@ class V8_EXPORT_PRIVATE JSIntrinsicLowering final ...@@ -58,7 +58,7 @@ class V8_EXPORT_PRIVATE JSIntrinsicLowering final
Reduction ReduceIsInstanceType(Node* node, InstanceType instance_type); Reduction ReduceIsInstanceType(Node* node, InstanceType instance_type);
Reduction ReduceIsJSReceiver(Node* node); Reduction ReduceIsJSReceiver(Node* node);
Reduction ReduceIsSmi(Node* node); Reduction ReduceIsSmi(Node* node);
Reduction ReduceStaticAssert(Node* node); Reduction ReduceTurbofanStaticAssert(Node* node);
Reduction ReduceToLength(Node* node); Reduction ReduceToLength(Node* node);
Reduction ReduceToObject(Node* node); Reduction ReduceToObject(Node* node);
Reduction ReduceToString(Node* node); Reduction ReduceToString(Node* node);
......
...@@ -113,6 +113,26 @@ base::Optional<MapRef> GetStableMapFromObjectType(JSHeapBroker* broker, ...@@ -113,6 +113,26 @@ base::Optional<MapRef> GetStableMapFromObjectType(JSHeapBroker* broker,
return {}; 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 } // namespace
Reduction TypedOptimization::ReduceConvertReceiver(Node* node) { Reduction TypedOptimization::ReduceConvertReceiver(Node* node) {
...@@ -507,7 +527,10 @@ Reduction TypedOptimization::ReduceSameValue(Node* node) { ...@@ -507,7 +527,10 @@ Reduction TypedOptimization::ReduceSameValue(Node* node) {
Node* const rhs = NodeProperties::GetValueInput(node, 1); Node* const rhs = NodeProperties::GetValueInput(node, 1);
Type const lhs_type = NodeProperties::GetType(lhs); Type const lhs_type = NodeProperties::GetType(lhs);
Type const rhs_type = NodeProperties::GetType(rhs); 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 // SameValue(x,x) => #true
return Replace(jsgraph()->TrueConstant()); return Replace(jsgraph()->TrueConstant());
} else if (lhs_type.Is(Type::Unique()) && rhs_type.Is(Type::Unique())) { } else if (lhs_type.Is(Type::Unique()) && rhs_type.Is(Type::Unique())) {
......
...@@ -1277,7 +1277,7 @@ RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) { ...@@ -1277,7 +1277,7 @@ RUNTIME_FUNCTION(Runtime_FreezeWasmLazyCompilation) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
RUNTIME_FUNCTION(Runtime_StaticAssert) { RUNTIME_FUNCTION(Runtime_TurbofanStaticAssert) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
// Always lowered to StaticAssert node in Turbofan, so we should never get // Always lowered to StaticAssert node in Turbofan, so we should never get
// here in compiled code. // here in compiled code.
......
...@@ -519,7 +519,7 @@ namespace internal { ...@@ -519,7 +519,7 @@ namespace internal {
F(WasmNumInterpretedCalls, 1, 1) \ F(WasmNumInterpretedCalls, 1, 1) \
F(WasmTraceMemory, 1, 1) \ F(WasmTraceMemory, 1, 1) \
F(SetWasmThreadsEnabled, 1, 1) \ F(SetWasmThreadsEnabled, 1, 1) \
F(StaticAssert, 1, 1) \ F(TurbofanStaticAssert, 1, 1) \
F(EnableCodeLoggingForTesting, 0, 1) F(EnableCodeLoggingForTesting, 0, 1)
#define FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \ #define FOR_EACH_INTRINSIC_TYPEDARRAY(F, I) \
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
// Check that constant-folding of arithmetic results in identical nodes. // Check that constant-folding of arithmetic results in identical nodes.
(function() { (function() {
function foo(x) { function foo(x) {
%StaticAssert(1 * x == x + 0); %TurbofanStaticAssert(1 * x == x + 0);
} }
foo(121); foo(121);
foo(122); foo(122);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment