summaryrefslogtreecommitdiff
path: root/compiler/optimizing/induction_var_range.cc
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2023-04-05 10:33:07 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2023-04-27 10:52:39 +0000
commit79dc217688a774fc532584f6551a0aec8b45bc4a (patch)
tree5abfe4bd90364e66b593088ab4d1b407b51dada5 /compiler/optimizing/induction_var_range.cc
parentd60aff547dedefc35265ce57707d406e8ccc4dc6 (diff)
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
Diffstat (limited to 'compiler/optimizing/induction_var_range.cc')
-rw-r--r--compiler/optimizing/induction_var_range.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/optimizing/induction_var_range.cc b/compiler/optimizing/induction_var_range.cc
index 9b78699ead..107a2c38da 100644
--- a/compiler/optimizing/induction_var_range.cc
+++ b/compiler/optimizing/induction_var_range.cc
@@ -171,8 +171,9 @@ bool UseFullTripCount(const HBasicBlock* context, const HLoopInformation* loop,
// one edge leaving the loop. The loop header is the only block that's both inside
// the loop and not in the loop body.
DCHECK(GetLoopControl(loop)->IsIf());
- DCHECK_NE(loop->Contains(*GetLoopControl(loop)->AsIf()->IfTrueSuccessor()),
- loop->Contains(*GetLoopControl(loop)->AsIf()->IfFalseSuccessor()));
+ // TODO: Remove "OrNull".
+ DCHECK_NE(loop->Contains(*GetLoopControl(loop)->AsIfOrNull()->IfTrueSuccessor()),
+ loop->Contains(*GetLoopControl(loop)->AsIfOrNull()->IfFalseSuccessor()));
if (loop->Contains(*context)) {
// Use the full trip count if determining the maximum and context is not in the loop body.
DCHECK_NE(context == loop->GetHeader(), IsContextInBody(context, loop));
@@ -182,8 +183,10 @@ bool UseFullTripCount(const HBasicBlock* context, const HLoopInformation* loop,
// as long as the `context` is dominated by the loop control exit block.
// If there are additional exit edges, the value is unknown on those paths.
HInstruction* loop_control = GetLoopControl(loop);
- HBasicBlock* then_block = loop_control->AsIf()->IfTrueSuccessor();
- HBasicBlock* else_block = loop_control->AsIf()->IfFalseSuccessor();
+ // TODO: Remove "OrNull".
+ HBasicBlock* then_block = loop_control->AsIfOrNull()->IfTrueSuccessor();
+ // TODO: Remove "OrNull".
+ HBasicBlock* else_block = loop_control->AsIfOrNull()->IfFalseSuccessor();
HBasicBlock* loop_exit_block = loop->Contains(*then_block) ? else_block : then_block;
return loop_exit_block->Dominates(context);
}
@@ -735,13 +738,15 @@ InductionVarRange::Value InductionVarRange::GetFetch(const HBasicBlock* context,
return is_min ? Value(0) : Value(std::numeric_limits<int32_t>::max());
} else if (instruction->InputAt(0)->IsNewArray()) {
return GetFetch(
- context, loop, instruction->InputAt(0)->AsNewArray()->GetLength(), trip, is_min);
+ // TODO: Remove "OrNull".
+ context, loop, instruction->InputAt(0)->AsNewArrayOrNull()->GetLength(), trip, is_min);
}
} else if (instruction->IsTypeConversion()) {
// Since analysis is 32-bit (or narrower), chase beyond widening along the path.
// For example, this discovers the length in: for (long i = 0; i < a.length; i++);
- if (instruction->AsTypeConversion()->GetInputType() == DataType::Type::kInt32 &&
- instruction->AsTypeConversion()->GetResultType() == DataType::Type::kInt64) {
+ // TODO: Remove "OrNull".
+ if (instruction->AsTypeConversionOrNull()->GetInputType() == DataType::Type::kInt32 &&
+ instruction->AsTypeConversionOrNull()->GetResultType() == DataType::Type::kInt64) {
return GetFetch(context, loop, instruction->InputAt(0), trip, is_min);
}
}