Skip to content

Commit 330f746

Browse files
committed
[MERGE chakra-core#4474 @sigatrev] ARM64: use 2 instructions for InlineeCallInfo
Merge pull request chakra-core#4474 from sigatrev:inlineeCallInfo minor optimization
2 parents 376876a + 9172f37 commit 330f746

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

lib/Backend/arm64/EncoderMD.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,12 @@ EncoderMD::Encode(IR::Instr *instr, BYTE *pc, BYTE* beginCodeAddress)
13751375
{
13761376
if (instr->isInlineeEntryInstr)
13771377
{
1378+
size_t inlineeOffset = m_pc - m_encoder->m_encodeBuffer;
1379+
size_t argCount = instr->AsLabelInstr()->GetOffset();
1380+
Assert(inlineeOffset == (inlineeOffset & 0x0FFFFFFF));
1381+
13781382
intptr_t inlineeCallInfo = 0;
1379-
const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, instr->AsLabelInstr()->GetOffset(), m_pc - m_encoder->m_encodeBuffer);
1383+
const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, argCount, inlineeOffset);
13801384
Assert(encodeResult);
13811385
//We are re-using offset to save the inlineeCallInfo which will be patched in ApplyRelocs
13821386
//This is a cleaner way to patch MOVW\MOVT pair with the right inlineeCallInfo

lib/Backend/arm64/LegalizeMD.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,12 @@ void LegalizeMD::LegalizeLDIMM(IR::Instr * instr, IntConstType immed)
669669
// This is done by having the load be from a label operand, which is later
670670
// changed such that its offset is the correct value to ldimm
671671

672+
// InlineeCallInfo is encoded as ((offset into function) << 4) | (argCount & 0xF).
673+
// This will fit into 32 bits as long as the function has less than 2^26 instructions, which should be always.
674+
672675
// The assembly generated becomes something like
673676
// Label (offset:fake)
674677
// MOVZ DST, Label
675-
// MOVK DST, Label
676-
// MOVK DST, Label
677678
// MOVK DST, Label <- was the LDIMM
678679

679680
Assert(Security::DontEncode(instr->GetSrc1()));
@@ -689,15 +690,11 @@ void LegalizeMD::LegalizeLDIMM(IR::Instr * instr, IntConstType immed)
689690

690691
// We'll handle splitting this up to properly load the immediates now
691692
// Typically (and worst case) we'll need to load 64 bits.
692-
IR::Instr* bits48_63 = IR::Instr::New(Js::OpCode::MOVZ, instr->GetDst(), target, IR::IntConstOpnd::New(48, IRType::TyUint8, instr->m_func, true), instr->m_func);
693-
instr->InsertBefore(bits48_63);
694-
IR::Instr* bits32_47 = IR::Instr::New(Js::OpCode::MOVK, instr->GetDst(), target, IR::IntConstOpnd::New(32, IRType::TyUint8, instr->m_func, true), instr->m_func);
695-
instr->InsertBefore(bits32_47);
696-
IR::Instr* bits16_31 = IR::Instr::New(Js::OpCode::MOVK, instr->GetDst(), target, IR::IntConstOpnd::New(16, IRType::TyUint8, instr->m_func, true), instr->m_func);
697-
instr->InsertBefore(bits16_31);
693+
IR::Instr* bits0_15 = IR::Instr::New(Js::OpCode::MOVZ, instr->GetDst(), target, IR::IntConstOpnd::New(0, IRType::TyUint8, instr->m_func, true), instr->m_func);
694+
instr->InsertBefore(bits0_15);
698695

699696
instr->ReplaceSrc1(target);
700-
instr->SetSrc2(IR::IntConstOpnd::New(0, IRType::TyUint8, instr->m_func, true));
697+
instr->SetSrc2(IR::IntConstOpnd::New(16, IRType::TyUint8, instr->m_func, true));
701698
instr->m_opcode = Js::OpCode::MOVK;
702699

703700
instr->isInlineeEntryInstr = false;

0 commit comments

Comments
 (0)