diff options
| author | 2017-11-21 14:44:54 -0800 | |
|---|---|---|
| committer | 2017-11-22 10:46:57 -0800 | |
| commit | cebb5e709af5ed5b475a56743f984967d991e7b9 (patch) | |
| tree | db2b6c243606979c905ec10a5cced999eba0f209 /compiler/optimizing | |
| parent | 8cceb1faf894c26b89ceacd3d60599fe0b4b93b7 (diff) | |
type conversion elimination for constant input
type conversion on constant input can be eliminated if the constant
value falls in the result type's range.
Test: run-test on host, 711-checker-type-conversion
Change-Id: I372139d681aa06fa6e760d7814c86ac949292813
Diffstat (limited to 'compiler/optimizing')
| -rw-r--r-- | compiler/optimizing/data_type.h | 13 | ||||
| -rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 10 |
2 files changed, 23 insertions, 0 deletions
diff --git a/compiler/optimizing/data_type.h b/compiler/optimizing/data_type.h index 75a7fbe6ca..d253036479 100644 --- a/compiler/optimizing/data_type.h +++ b/compiler/optimizing/data_type.h @@ -186,6 +186,7 @@ class DataType { } static bool IsTypeConversionImplicit(Type input_type, Type result_type); + static bool IsTypeConversionImplicit(int64_t value, Type result_type); static const char* PrettyDescriptor(Type type); @@ -213,6 +214,18 @@ inline bool DataType::IsTypeConversionImplicit(Type input_type, Type result_type MaxValueOfIntegralType(input_type) <= MaxValueOfIntegralType(result_type)); } +inline bool DataType::IsTypeConversionImplicit(int64_t value, Type result_type) { + if (IsIntegralType(result_type) && result_type != Type::kInt64) { + // If the constant value falls in the range of the result_type, type + // conversion isn't needed. + return value >= MinValueOfIntegralType(result_type) && + value <= MaxValueOfIntegralType(result_type); + } + // Conversion isn't implicit if it's into non-integer types, or 64-bit int + // which may have different number of registers. + return false; +} + } // namespace art #endif // ART_COMPILER_OPTIMIZING_DATA_TYPE_H_ diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index fbfee12be9..a6dfa475eb 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -1159,6 +1159,16 @@ void InstructionSimplifierVisitor::VisitTypeConversion(HTypeConversion* instruct RecordSimplification(); return; } + } else if (input->IsIntConstant()) { + // Try to eliminate type conversion on int constant whose value falls into + // the range of the result type. + int32_t value = input->AsIntConstant()->GetValue(); + if (DataType::IsTypeConversionImplicit(value, result_type)) { + instruction->ReplaceWith(input); + instruction->GetBlock()->RemoveInstruction(instruction); + RecordSimplification(); + return; + } } } |