Skip to content

Commit

Permalink
Keep the Ret instruction to extend the lifetime of the return regis…
Browse files Browse the repository at this point in the history
…ter(s) then remove it in FinalLower.

Fixing a bug in wasm int64 returns on x86  where edx is reused to reload a spilled value for eax.
  • Loading branch information
Cellule committed Jun 29, 2017
1 parent ca581d9 commit bb4e9fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23589,6 +23589,7 @@ Lowerer::ValidOpcodeAfterLower(IR::Instr* instr, Func * func)
}
switch (opcode)
{
case Js::OpCode::Ret:
case Js::OpCode::Label:
case Js::OpCode::StatementBoundary:
case Js::OpCode::DeletedNonHelperBranch:
Expand Down
16 changes: 10 additions & 6 deletions lib/Backend/LowerMDShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,10 @@ LowererMD::LowerRet(IR::Instr * retInstr)
retInstr->SetSrc1(lowOpnd);

// Mov high bits to edx
IR::RegOpnd* regEdx = IR::RegOpnd::New(nullptr, RegEDX, regType, this->m_func);
IR::RegOpnd* regEdx = IR::RegOpnd::New(regType, this->m_func);
regEdx->SetReg(RegEDX);
Lowerer::InsertMove(regEdx, highOpnd, retInstr);
retInstr->SetSrc2(regEdx);
}
#endif
break;
Expand Down Expand Up @@ -910,17 +912,19 @@ LowererMD::LowerRet(IR::Instr * retInstr)
Assert(UNREACHED);
}

retReg = IR::RegOpnd::New(nullptr, lowererMDArch.GetRegReturnAsmJs(regType), regType, m_func);
retReg = IR::RegOpnd::New(regType, m_func);
retReg->SetReg(lowererMDArch.GetRegReturnAsmJs(regType));
}
else
#endif
{
retReg = IR::RegOpnd::New(nullptr, lowererMDArch.GetRegReturn(TyMachReg), TyMachReg, m_func);
retReg = IR::RegOpnd::New(TyMachReg, m_func);
retReg->SetReg(lowererMDArch.GetRegReturn(TyMachReg));
}

retInstr->SetDst(retReg);

return this->ChangeToAssign(retInstr);
Lowerer::InsertMove(retReg, retInstr->UnlinkSrc1(), retInstr);
retInstr->SetSrc1(retReg);
return retInstr;
}

///----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions lib/Backend/amd64/LowererMDArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,9 @@ LowererMDArch::FinalLower()
{
switch (instr->m_opcode)
{
case Js::OpCode::Ret:
instr->Remove();
break;
case Js::OpCode::LdArgSize:
Assert(this->m_func->HasTry());
instr->m_opcode = Js::OpCode::MOV;
Expand Down
3 changes: 3 additions & 0 deletions lib/Backend/arm/LowerMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8675,6 +8675,9 @@ LowererMD::FinalLower()

switch (instr->m_opcode)
{
case Js::OpCode::Ret:
instr->Remove();
break;
case Js::OpCode::Leave:
Assert(this->m_func->DoOptimizeTry() && !this->m_func->IsLoopBodyInTry());
instrPrev = this->LowerLeave(instr, instr->AsBranchInstr()->GetTarget(), true /*fromFinalLower*/);
Expand Down
3 changes: 3 additions & 0 deletions lib/Backend/i386/LowererMDArch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3970,6 +3970,9 @@ LowererMDArch::FinalLower()
{
switch (instr->m_opcode)
{
case Js::OpCode::Ret:
instr->Remove();
break;
case Js::OpCode::Leave:
Assert(this->m_func->DoOptimizeTry() && !this->m_func->IsLoopBodyInTry());
this->lowererMD->LowerLeave(instr, instr->AsBranchInstr()->GetTarget(), true /*fromFinalLower*/);
Expand Down

0 comments on commit bb4e9fa

Please sign in to comment.