diff options
| author | 2016-03-14 19:13:14 +0000 | |
|---|---|---|
| committer | 2016-03-14 19:13:14 +0000 | |
| commit | 0b2c1922cc29a7939f747f60d80240a9fb22547c (patch) | |
| tree | 604f2e06372c7877c69aa18458d047fbdeafd323 /compiler/optimizing | |
| parent | de836594741c8547afb2a680e1d442dcc27cfbe5 (diff) | |
| parent | 625090fe9bf47d8d735c9a66cbf491de3a3e3765 (diff) | |
Merge "Optimizing: Fix TypeConversion(And(x, const)) simplification."
Diffstat (limited to 'compiler/optimizing')
| -rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 049901b882..69dad697a6 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -867,9 +867,7 @@ void InstructionSimplifierVisitor::VisitTypeConversion(HTypeConversion* instruct return; } } - } else if (input->IsAnd() && - Primitive::IsIntegralType(result_type) && - input->HasOnlyOneNonEnvironmentUse()) { + } else if (input->IsAnd() && Primitive::IsIntegralType(result_type)) { DCHECK(Primitive::IsIntegralType(input_type)); HAnd* input_and = input->AsAnd(); HConstant* constant = input_and->GetConstantRight(); @@ -879,10 +877,18 @@ void InstructionSimplifierVisitor::VisitTypeConversion(HTypeConversion* instruct size_t trailing_ones = CTZ(~static_cast<uint64_t>(value)); if (trailing_ones >= kBitsPerByte * Primitive::ComponentSize(result_type)) { // The `HAnd` is useless, for example in `(byte) (x & 0xff)`, get rid of it. - input_and->ReplaceWith(input_and->GetLeastConstantLeft()); - input_and->GetBlock()->RemoveInstruction(input_and); - RecordSimplification(); - return; + HInstruction* original_input = input_and->GetLeastConstantLeft(); + if (IsTypeConversionImplicit(original_input->GetType(), result_type)) { + instruction->ReplaceWith(original_input); + instruction->GetBlock()->RemoveInstruction(instruction); + RecordSimplification(); + return; + } else if (input->HasOnlyOneNonEnvironmentUse()) { + input_and->ReplaceWith(original_input); + input_and->GetBlock()->RemoveInstruction(input_and); + RecordSimplification(); + return; + } } } } |