Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: test/unittests/compiler/load-elimination-unittest.cc

Issue 2295643002: [turbofan] Extend LoadElimination to introduce TypeGuards. (Closed)
Patch Set: Fix assertion in SimplifiedLowering. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/simplified-lowering.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/load-elimination-unittest.cc
diff --git a/test/unittests/compiler/load-elimination-unittest.cc b/test/unittests/compiler/load-elimination-unittest.cc
index 1c5a8375015baae5d51f65067dfbd18a6c636e42..2306f72b4c32f1482a43f1373e11c678f43f943e 100644
--- a/test/unittests/compiler/load-elimination-unittest.cc
+++ b/test/unittests/compiler/load-elimination-unittest.cc
@@ -359,6 +359,64 @@ TEST_F(LoadEliminationTest, LoadFieldOnTrueBranchOfDiamond) {
EXPECT_EQ(load, r.replacement());
}
+TEST_F(LoadEliminationTest, LoadFieldWithTypeMismatch) {
+ Node* object = Parameter(Type::Any(), 0);
+ Node* value = Parameter(Type::Signed32(), 1);
+ Node* effect = graph()->start();
+ Node* control = graph()->start();
+ FieldAccess const access = {kTaggedBase,
+ kPointerSize,
+ MaybeHandle<Name>(),
+ Type::Unsigned31(),
+ MachineType::AnyTagged(),
+ kNoWriteBarrier};
+
+ StrictMock<MockAdvancedReducerEditor> editor;
+ LoadElimination load_elimination(&editor, jsgraph(), zone());
+
+ load_elimination.Reduce(graph()->start());
+
+ Node* store = effect = graph()->NewNode(simplified()->StoreField(access),
+ object, value, effect, control);
+ load_elimination.Reduce(effect);
+
+ Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect,
+ control);
+ EXPECT_CALL(editor,
+ ReplaceWithValue(load, IsTypeGuard(value, control), store, _));
+ Reduction r = load_elimination.Reduce(load);
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsTypeGuard(value, control));
+}
+
+TEST_F(LoadEliminationTest, LoadElementWithTypeMismatch) {
+ Node* object = Parameter(Type::Any(), 0);
+ Node* index = Parameter(Type::UnsignedSmall(), 1);
+ Node* value = Parameter(Type::Signed32(), 2);
+ Node* effect = graph()->start();
+ Node* control = graph()->start();
+ ElementAccess const access = {kTaggedBase, kPointerSize, Type::Unsigned31(),
+ MachineType::AnyTagged(), kNoWriteBarrier};
+
+ StrictMock<MockAdvancedReducerEditor> editor;
+ LoadElimination load_elimination(&editor, jsgraph(), zone());
+
+ load_elimination.Reduce(graph()->start());
+
+ Node* store = effect =
+ graph()->NewNode(simplified()->StoreElement(access), object, index, value,
+ effect, control);
+ load_elimination.Reduce(effect);
+
+ Node* load = graph()->NewNode(simplified()->LoadElement(access), object,
+ index, effect, control);
+ EXPECT_CALL(editor,
+ ReplaceWithValue(load, IsTypeGuard(value, control), store, _));
+ Reduction r = load_elimination.Reduce(load);
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsTypeGuard(value, control));
+}
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/simplified-lowering.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698