summaryrefslogtreecommitdiff
path: root/compiler/optimizing/instruction_simplifier_shared.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/instruction_simplifier_shared.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/instruction_simplifier_shared.cc')
-rw-r--r--compiler/optimizing/instruction_simplifier_shared.cc37
1 files changed, 25 insertions, 12 deletions
diff --git a/compiler/optimizing/instruction_simplifier_shared.cc b/compiler/optimizing/instruction_simplifier_shared.cc
index 34daae21ee..3357e53737 100644
--- a/compiler/optimizing/instruction_simplifier_shared.cc
+++ b/compiler/optimizing/instruction_simplifier_shared.cc
@@ -52,7 +52,8 @@ bool TrySimpleMultiplyAccumulatePatterns(HMul* mul,
} else {
DCHECK(input_binop->IsSub());
if (input_binop->GetRight()->IsConstant() &&
- input_binop->GetRight()->AsConstant()->IsMinusOne()) {
+ // TODO: Remove "OrNull".
+ input_binop->GetRight()->AsConstantOrNull()->IsMinusOne()) {
// Interpret
// a * (b - (-1))
// as
@@ -60,7 +61,8 @@ bool TrySimpleMultiplyAccumulatePatterns(HMul* mul,
input_b = input_binop->GetLeft();
op_kind = HInstruction::kAdd;
} else if (input_binop->GetLeft()->IsConstant() &&
- input_binop->GetLeft()->AsConstant()->IsOne()) {
+ // TODO: Remove "OrNull".
+ input_binop->GetLeft()->AsConstantOrNull()->IsOne()) {
// Interpret
// a * (1 - b)
// as
@@ -122,7 +124,8 @@ bool TryCombineMultiplyAccumulate(HMul* mul, InstructionSet isa) {
// whether all uses are on different control-flow paths (using dominance and
// reverse-dominance information) and only perform the merge when they are.
HInstruction* accumulator = nullptr;
- HBinaryOperation* binop = use->AsBinaryOperation();
+ // TODO: Remove "OrNull".
+ HBinaryOperation* binop = use->AsBinaryOperationOrNull();
HInstruction* binop_left = binop->GetLeft();
HInstruction* binop_right = binop->GetRight();
// Be careful after GVN. This should not happen since the `HMul` has only
@@ -175,11 +178,13 @@ bool TryCombineMultiplyAccumulate(HMul* mul, InstructionSet isa) {
HInstruction* left = mul->GetLeft();
HInstruction* right = mul->GetRight();
if ((right->IsAdd() || right->IsSub()) &&
- TrySimpleMultiplyAccumulatePatterns(mul, right->AsBinaryOperation(), left)) {
+ // TODO: Remove "OrNull".
+ TrySimpleMultiplyAccumulatePatterns(mul, right->AsBinaryOperationOrNull(), left)) {
return true;
}
if ((left->IsAdd() || left->IsSub()) &&
- TrySimpleMultiplyAccumulatePatterns(mul, left->AsBinaryOperation(), right)) {
+ // TODO: Remove "OrNull".
+ TrySimpleMultiplyAccumulatePatterns(mul, left->AsBinaryOperationOrNull(), right)) {
return true;
}
return false;
@@ -214,7 +219,8 @@ bool TryMergeNegatedInput(HBinaryOperation* op) {
// AND dst, src, tmp (respectively ORR, EOR)
// with
// BIC dst, src, mask (respectively ORN, EON)
- HInstruction* src = hnot->AsNot()->GetInput();
+ // TODO: Remove "OrNull".
+ HInstruction* src = hnot->AsNotOrNull()->GetInput();
HBitwiseNegatedRight* neg_op = new (hnot->GetBlock()->GetGraph()->GetAllocator())
HBitwiseNegatedRight(op->GetType(), op->GetKind(), hother, src, op->GetDexPc());
@@ -234,13 +240,15 @@ bool TryExtractArrayAccessAddress(HInstruction* access,
HInstruction* index,
size_t data_offset) {
if (index->IsConstant() ||
- (index->IsBoundsCheck() && index->AsBoundsCheck()->GetIndex()->IsConstant())) {
+ // TODO: Remove "OrNull".
+ (index->IsBoundsCheck() && index->AsBoundsCheckOrNull()->GetIndex()->IsConstant())) {
// When the index is a constant all the addressing can be fitted in the
// memory access instruction, so do not split the access.
return false;
}
if (access->IsArraySet() &&
- access->AsArraySet()->GetValue()->GetType() == DataType::Type::kReference) {
+ // TODO: Remove "OrNull".
+ access->AsArraySetOrNull()->GetValue()->GetType() == DataType::Type::kReference) {
// The access may require a runtime call or the original array pointer.
return false;
}
@@ -300,7 +308,8 @@ bool TryExtractVecArrayAccessAddress(HVecMemoryOperation* access, HInstruction*
for (const HUseListNode<HInstruction*>& use : index->GetUses()) {
HInstruction* user = use.GetUser();
if (user->IsVecMemoryOperation() && user != access) {
- HVecMemoryOperation* another_access = user->AsVecMemoryOperation();
+ // TODO: Remove "OrNull".
+ HVecMemoryOperation* another_access = user->AsVecMemoryOperationOrNull();
DataType::Type another_packed_type = another_access->GetPackedType();
uint32_t another_data_offset = mirror::Array::DataOffset(
DataType::Size(another_packed_type)).Uint32Value();
@@ -310,9 +319,13 @@ bool TryExtractVecArrayAccessAddress(HVecMemoryOperation* access, HInstruction*
break;
}
} else if (user->IsIntermediateAddressIndex()) {
- HIntermediateAddressIndex* another_access = user->AsIntermediateAddressIndex();
- uint32_t another_data_offset = another_access->GetOffset()->AsIntConstant()->GetValue();
- size_t another_component_shift = another_access->GetShift()->AsIntConstant()->GetValue();
+ // TODO: Remove "OrNull".
+ HIntermediateAddressIndex* another_access = user->AsIntermediateAddressIndexOrNull();
+ // TODO: Remove "OrNull".
+ uint32_t another_data_offset = another_access->GetOffset()->AsIntConstantOrNull()->GetValue();
+ // TODO: Remove "OrNull".
+ size_t another_component_shift =
+ another_access->GetShift()->AsIntConstantOrNull()->GetValue();
if (another_data_offset == data_offset && another_component_shift == component_shift) {
is_extracting_beneficial = true;
break;