From c50d67991682a9ae5e6215031a9852bbf018504b Mon Sep 17 00:00:00 2001 From: VladimĂ­r Marko Date: Fri, 4 Oct 2024 09:18:58 +0000 Subject: Reland "Calculate the number of out vregs." This reverts commit 434a327234f74eed3ef4072314d2e2bdb73e4dda. Reason for revert: Relanding with no change. The regressions that were the reason for the revert may reappear. However, these regressions are probably caused by subtle effects that are not directly related to this change. For example, a code size improvement can regress performance simply by moving the start of a loop from an aligned address to an unaligned address, or by splitting a loop across two cache lines. Bug: 358519867 Bug: 359722268 Change-Id: I997b8a4219418f79b3a5fc4e7e50817911f0a737 --- compiler/optimizing/instruction_simplifier.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'compiler/optimizing/instruction_simplifier.cc') diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index a09a9f0ead..cd2371d90c 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -2996,7 +2996,7 @@ static bool NoEscapeForStringBufferReference(HInstruction* reference, HInstructi return false; } -static bool TryReplaceStringBuilderAppend(HInvoke* invoke) { +static bool TryReplaceStringBuilderAppend(CodeGenerator* codegen, HInvoke* invoke) { DCHECK_EQ(invoke->GetIntrinsic(), Intrinsics::kStringBuilderToString); if (invoke->CanThrowIntoCatchBlock()) { return false; @@ -3153,11 +3153,25 @@ static bool TryReplaceStringBuilderAppend(HInvoke* invoke) { } } + // Calculate outgoing vregs, including padding for 64-bit arg alignment. + const PointerSize pointer_size = InstructionSetPointerSize(codegen->GetInstructionSet()); + const size_t method_vregs = static_cast(pointer_size) / kVRegSize; + uint32_t number_of_out_vregs = method_vregs; // For correct alignment padding; subtracted below. + for (uint32_t f = format; f != 0u; f >>= StringBuilderAppend::kBitsPerArg) { + auto a = enum_cast(f & StringBuilderAppend::kArgMask); + if (a == StringBuilderAppend::Argument::kLong || a == StringBuilderAppend::Argument::kDouble) { + number_of_out_vregs += /* alignment */ ((number_of_out_vregs) & 1u) + /* vregs */ 2u; + } else { + number_of_out_vregs += /* vregs */ 1u; + } + } + number_of_out_vregs -= method_vregs; + // Create replacement instruction. HIntConstant* fmt = block->GetGraph()->GetIntConstant(static_cast(format)); ArenaAllocator* allocator = block->GetGraph()->GetAllocator(); HStringBuilderAppend* append = new (allocator) HStringBuilderAppend( - fmt, num_args, has_fp_args, allocator, invoke->GetDexPc()); + fmt, num_args, number_of_out_vregs, has_fp_args, allocator, invoke->GetDexPc()); append->SetReferenceTypeInfoIfValid(invoke->GetReferenceTypeInfo()); for (size_t i = 0; i != num_args; ++i) { append->SetArgumentAt(i, args[num_args - 1u - i]); @@ -3202,7 +3216,7 @@ void InstructionSimplifierVisitor::SimplifyAllocationIntrinsic(HInvoke* invoke) RecordSimplification(); } } else if (invoke->GetIntrinsic() == Intrinsics::kStringBuilderToString && - TryReplaceStringBuilderAppend(invoke)) { + TryReplaceStringBuilderAppend(codegen_, invoke)) { RecordSimplification(); } } -- cgit v1.2.3-59-g8ed1b