Ensure object ArraySet with null value does not need a type check.
The art::PrepareForRegisterAllocation visitor can remove an
art::BoundType instruction as value input of an
art::ArraySet instruction, possibly replacing it with an
art::NullConstant. If this happens, remove the need for a
type check in this art::ArraySet.
Bug: 27638110
Change-Id: I6270f8a8e22822a24d8a5919df427ca9c64d121b
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc
index 4f1e90c..3a9d242 100644
--- a/compiler/optimizing/graph_visualizer.cc
+++ b/compiler/optimizing/graph_visualizer.cc
@@ -382,6 +382,8 @@
void VisitArraySet(HArraySet* array_set) OVERRIDE {
StartAttributeStream("value_can_be_null") << std::boolalpha
<< array_set->GetValueCanBeNull() << std::noboolalpha;
+ StartAttributeStream("needs_type_check") << std::boolalpha
+ << array_set->NeedsTypeCheck() << std::noboolalpha;
}
void VisitCompare(HCompare* compare) OVERRIDE {
diff --git a/compiler/optimizing/prepare_for_register_allocation.cc b/compiler/optimizing/prepare_for_register_allocation.cc
index 0ad104e..fc72727 100644
--- a/compiler/optimizing/prepare_for_register_allocation.cc
+++ b/compiler/optimizing/prepare_for_register_allocation.cc
@@ -47,6 +47,19 @@
bound_type->GetBlock()->RemoveInstruction(bound_type);
}
+void PrepareForRegisterAllocation::VisitArraySet(HArraySet* instruction) {
+ HInstruction* value = instruction->GetValue();
+ // PrepareForRegisterAllocation::VisitBoundType may have replaced a
+ // BoundType (as value input of this ArraySet) with a NullConstant.
+ // If so, this ArraySet no longer needs a type check.
+ if (value->IsNullConstant()) {
+ DCHECK_EQ(value->GetType(), Primitive::kPrimNot);
+ if (instruction->NeedsTypeCheck()) {
+ instruction->ClearNeedsTypeCheck();
+ }
+ }
+}
+
void PrepareForRegisterAllocation::VisitClinitCheck(HClinitCheck* check) {
// Try to find a static invoke or a new-instance from which this check originated.
HInstruction* implicit_clinit = nullptr;
diff --git a/compiler/optimizing/prepare_for_register_allocation.h b/compiler/optimizing/prepare_for_register_allocation.h
index c90724c..a679148 100644
--- a/compiler/optimizing/prepare_for_register_allocation.h
+++ b/compiler/optimizing/prepare_for_register_allocation.h
@@ -40,6 +40,7 @@
void VisitDivZeroCheck(HDivZeroCheck* check) OVERRIDE;
void VisitBoundsCheck(HBoundsCheck* check) OVERRIDE;
void VisitBoundType(HBoundType* bound_type) OVERRIDE;
+ void VisitArraySet(HArraySet* instruction) OVERRIDE;
void VisitClinitCheck(HClinitCheck* check) OVERRIDE;
void VisitCondition(HCondition* condition) OVERRIDE;
void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE;