From 79dc217688a774fc532584f6551a0aec8b45bc4a Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 5 Apr 2023 10:33:07 +0000 Subject: Optimizing: Rename `As##type` to `As##type##OrNull`. The null type check in the current implementation of `HInstruction::As##type()` often cannot be optimized away by clang++. It is therefore beneficial to have two functions HInstruction::As##type() HInstruction::As##type##OrNull() where the first function never returns null but the second one can return null. The additional text "OrNull" shall also flag the possibility of yielding null to the developer which may help avoid bugs similar to what we have seen previously. This requires renaming the existing function that can return null and introducing new function that cannot. However, defining the new function `HInstruction::As##type()` in the same change as renaming the old one would risk introducing bugs by missing a rename. Therefore we simply rename the old function here and the new function shall be introduced in a separate change with all behavioral changes being explicit. Test: m test-art-host-gtest Test: testrunner.py --host --optimizing Test: buildbot-build.sh --target Bug: 181943478 Change-Id: I4defd85038e28fe3506903ba3f33f723682b3298 --- compiler/optimizing/constant_folding_test.cc | 42 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'compiler/optimizing/constant_folding_test.cc') diff --git a/compiler/optimizing/constant_folding_test.cc b/compiler/optimizing/constant_folding_test.cc index 741fd3f822..4573dce4aa 100644 --- a/compiler/optimizing/constant_folding_test.cc +++ b/compiler/optimizing/constant_folding_test.cc @@ -128,7 +128,8 @@ TEST_F(ConstantFoldingTest, IntConstantFoldingNegation) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsIntConstant()); - ASSERT_EQ(inst->AsIntConstant()->GetValue(), -1); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsIntConstantOrNull()->GetValue(), -1); }; // Expected difference after dead code elimination. @@ -189,7 +190,8 @@ TEST_F(ConstantFoldingTest, LongConstantFoldingNegation) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsLongConstant()); - ASSERT_EQ(inst->AsLongConstant()->GetValue(), INT64_C(-4294967296)); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsLongConstantOrNull()->GetValue(), INT64_C(-4294967296)); }; // Expected difference after dead code elimination. @@ -250,7 +252,8 @@ TEST_F(ConstantFoldingTest, IntConstantFoldingOnAddition1) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsIntConstant()); - ASSERT_EQ(inst->AsIntConstant()->GetValue(), 3); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsIntConstantOrNull()->GetValue(), 3); }; // Expected difference after dead code elimination. @@ -329,13 +332,16 @@ TEST_F(ConstantFoldingTest, IntConstantFoldingOnAddition2) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst1 = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst1->IsIntConstant()); - ASSERT_EQ(inst1->AsIntConstant()->GetValue(), 12); + // TODO: Remove "OrNull". + ASSERT_EQ(inst1->AsIntConstantOrNull()->GetValue(), 12); HInstruction* inst2 = inst1->GetPrevious(); ASSERT_TRUE(inst2->IsIntConstant()); - ASSERT_EQ(inst2->AsIntConstant()->GetValue(), 9); + // TODO: Remove "OrNull". + ASSERT_EQ(inst2->AsIntConstantOrNull()->GetValue(), 9); HInstruction* inst3 = inst2->GetPrevious(); ASSERT_TRUE(inst3->IsIntConstant()); - ASSERT_EQ(inst3->AsIntConstant()->GetValue(), 3); + // TODO: Remove "OrNull". + ASSERT_EQ(inst3->AsIntConstantOrNull()->GetValue(), 3); }; // Expected difference after dead code elimination. @@ -400,7 +406,8 @@ TEST_F(ConstantFoldingTest, IntConstantFoldingOnSubtraction) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsIntConstant()); - ASSERT_EQ(inst->AsIntConstant()->GetValue(), 1); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsIntConstantOrNull()->GetValue(), 1); }; // Expected difference after dead code elimination. @@ -463,7 +470,8 @@ TEST_F(ConstantFoldingTest, LongConstantFoldingOnAddition) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsLongConstant()); - ASSERT_EQ(inst->AsLongConstant()->GetValue(), 3); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsLongConstantOrNull()->GetValue(), 3); }; // Expected difference after dead code elimination. @@ -527,7 +535,8 @@ TEST_F(ConstantFoldingTest, LongConstantFoldingOnSubtraction) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsLongConstant()); - ASSERT_EQ(inst->AsLongConstant()->GetValue(), 1); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsLongConstantOrNull()->GetValue(), 1); }; // Expected difference after dead code elimination. @@ -627,16 +636,20 @@ TEST_F(ConstantFoldingTest, IntConstantFoldingAndJumps) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst1 = graph->GetBlocks()[4]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst1->IsIntConstant()); - ASSERT_EQ(inst1->AsIntConstant()->GetValue(), 20); + // TODO: Remove "OrNull". + ASSERT_EQ(inst1->AsIntConstantOrNull()->GetValue(), 20); HInstruction* inst2 = inst1->GetPrevious(); ASSERT_TRUE(inst2->IsIntConstant()); - ASSERT_EQ(inst2->AsIntConstant()->GetValue(), 12); + // TODO: Remove "OrNull". + ASSERT_EQ(inst2->AsIntConstantOrNull()->GetValue(), 12); HInstruction* inst3 = inst2->GetPrevious(); ASSERT_TRUE(inst3->IsIntConstant()); - ASSERT_EQ(inst3->AsIntConstant()->GetValue(), 7); + // TODO: Remove "OrNull". + ASSERT_EQ(inst3->AsIntConstantOrNull()->GetValue(), 7); HInstruction* inst4 = inst3->GetPrevious(); ASSERT_TRUE(inst4->IsIntConstant()); - ASSERT_EQ(inst4->AsIntConstant()->GetValue(), 3); + // TODO: Remove "OrNull". + ASSERT_EQ(inst4->AsIntConstantOrNull()->GetValue(), 3); }; // Expected difference after dead code elimination. @@ -712,7 +725,8 @@ TEST_F(ConstantFoldingTest, ConstantCondition) { auto check_after_cf = [](HGraph* graph) { HInstruction* inst = graph->GetBlocks()[1]->GetFirstInstruction()->InputAt(0); ASSERT_TRUE(inst->IsIntConstant()); - ASSERT_EQ(inst->AsIntConstant()->GetValue(), 1); + // TODO: Remove "OrNull". + ASSERT_EQ(inst->AsIntConstantOrNull()->GetValue(), 1); }; // Expected graph after dead code elimination. -- cgit v1.2.3-59-g8ed1b