diff options
author | 2024-02-06 18:35:30 +0000 | |
---|---|---|
committer | 2024-02-08 16:21:08 +0000 | |
commit | 3fc3c91394f86fba4051a7150907c6edec49511a (patch) | |
tree | aac2e5bee0b041e55da5210254c8ec4d77c5762a /compiler/optimizing/instruction_simplifier.cc | |
parent | 899cecf6daa9e463b3115fa343aa62777c77baba (diff) |
Fix UShr/Shr(Shl(x, N), N) simplification
Do not introduce new implicit type conversions during simplification
otherwise we could have unexpected pattern
<<ImplicitConv>> TypeConversion
<<ExplicitConv>> TypeConversonn [<<ImplicitConv>>]
that leads to crash.
Test: testrunner.py --optimizing
Bug: 323462814
Change-Id: I7f2cb7e778712e86f3e41b86945a52eac7036050
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
-rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 5db8235e29..44d624883d 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -450,15 +450,22 @@ static bool TryReplaceShiftsByConstantWithTypeConversion(HBinaryOperation *instr bool is_signed = instruction->IsShr(); DataType::Type conv_type = is_signed ? source_integral_type : DataType::ToUnsigned(source_integral_type); + + DCHECK(DataType::IsTypeConversionImplicit(conv_type, instruction->GetResultType())); + HInstruction* shl_value = shl->GetLeft(); HBasicBlock *block = instruction->GetBlock(); - HTypeConversion* new_conversion = - new (block->GetGraph()->GetAllocator()) HTypeConversion(conv_type, shl_value); - - DCHECK(DataType::IsTypeConversionImplicit(conv_type, instruction->GetResultType())); + // We shouldn't introduce new implicit type conversions during simplification. + if (DataType::IsTypeConversionImplicit(shl_value->GetType(), conv_type)) { + instruction->ReplaceWith(shl_value); + instruction->GetBlock()->RemoveInstruction(instruction); + } else { + HTypeConversion* new_conversion = + new (block->GetGraph()->GetAllocator()) HTypeConversion(conv_type, shl_value); + block->ReplaceAndRemoveInstructionWith(instruction, new_conversion); + } - block->ReplaceAndRemoveInstructionWith(instruction, new_conversion); shl->GetBlock()->RemoveInstruction(shl); return true; |