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: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#61472}
This commit is contained in:
parent
eb04aaab26
commit
37ab663ae5
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -113,6 +113,26 @@ base::Optional<MapRef> 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())) {
|
||||
|
@ -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.
|
||||
|
@ -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) \
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user