summaryrefslogtreecommitdiff
path: root/compiler/optimizing/nodes_test.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2025-01-17 11:52:54 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2025-01-17 05:57:44 -0800
commit564ffff5b472f3a2dc38c2ab51a78f2d0e3f7ea8 (patch)
tree9efdcdeb41b9778a00b1fcd2256d09d1dea32646 /compiler/optimizing/nodes_test.cc
parentf5cca5b0592fdb9ecc836dc9158ba5d63e0c1c05 (diff)
Optimizing: Fix `InsertInputAt()`.
Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Change-Id: I500faee42b02dbc72474e30fa2a3c0388ae86674
Diffstat (limited to 'compiler/optimizing/nodes_test.cc')
-rw-r--r--compiler/optimizing/nodes_test.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler/optimizing/nodes_test.cc b/compiler/optimizing/nodes_test.cc
index 0302298b9c..5f71d053c6 100644
--- a/compiler/optimizing/nodes_test.cc
+++ b/compiler/optimizing/nodes_test.cc
@@ -197,6 +197,36 @@ TEST_F(NodeTest, AddInstruction) {
ASSERT_TRUE(parameter->GetUses().HasExactlyOneElement());
}
+TEST_F(NodeTest, InsertDuplicateInstructionAt) {
+ HBasicBlock* ret = InitEntryMainExitGraphWithReturnVoid();
+ HInstruction* const0 = graph_->GetIntConstant(0);
+ HInstruction* const1 = graph_->GetIntConstant(1);
+ HInstruction* const2 = graph_->GetIntConstant(0);
+ HInstruction* const3 = graph_->GetIntConstant(1);
+
+ // We should be able to insert a duplicate input to `HPhi`s if we want to
+ // make a graph transformation that adds another predecessor to a block.
+
+ // This used to accidentally end up with correct use information but unexpectedly
+ // using the old `HUseListNode<>` for the new use and the new one for the old use.
+ HPhi* phi1 = MakePhi(ret, {const0, const1});
+ struct AccessProtected : HVariableInputSizeInstruction {
+ using HVariableInputSizeInstruction::InputRecordAt;
+ };
+ const HUseListNode<HInstruction*>* old_use_node_before =
+ std::addressof(*(phi1->*&AccessProtected::InputRecordAt)(1u).GetUseNode());
+ phi1->InsertInputAt(1u, const1); // Moves the old use from position 1 to position 2.
+ const HUseListNode<HInstruction*>* old_use_node_after =
+ std::addressof(*(phi1->*&AccessProtected::InputRecordAt)(2u).GetUseNode());
+ EXPECT_EQ(old_use_node_before, old_use_node_after);
+ EXPECT_EQ(1u, (phi1->*&AccessProtected::InputRecordAt)(1u).GetUseNode()->GetIndex());
+ EXPECT_EQ(2u, (phi1->*&AccessProtected::InputRecordAt)(2u).GetUseNode()->GetIndex());
+
+ // This used to hit a `DCHECK()`.
+ HPhi* phi2 = MakePhi(ret, {const2, const3, const3});
+ phi2->InsertInputAt(1u, const3);
+}
+
TEST_F(NodeTest, ParentEnvironment) {
HGraph* graph = CreateGraph();
HBasicBlock* entry = new (GetAllocator()) HBasicBlock(graph);