Skip to content

Commit

Permalink
[MERGE #5671 @sigatrev] enable IsIn optimization for addrOpnds
Browse files Browse the repository at this point in the history
Merge pull request #5671 from sigatrev:isInAddr

numeric literal copy proped to var opnds are handled as addrOpnds. This change allows handling of addr opnds for the IsIn optimization, allowing us to optimize ```if (0 in array) ...```.
  • Loading branch information
sigatrev committed Sep 8, 2018
2 parents 78dcd87 + 6bd18b7 commit e565611
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/Backend/GlobOptArrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ bool GlobOpt::ArraySrcOpt::CheckOpCode()
return false;
}

if (instr->GetSrc1()->IsAddrOpnd())
{
const Js::Var val = instr->GetSrc1()->AsAddrOpnd()->m_address;
if (Js::TaggedInt::Is(val))
{
originalIndexOpnd = instr->UnlinkSrc1();
instr->SetSrc1(IR::IntConstOpnd::New(Js::TaggedInt::ToInt32(val), TyInt32, instr->m_func));
}
}

if (!instr->GetSrc1()->IsRegOpnd() && !instr->GetSrc1()->IsIntConstOpnd())
{
return false;
Expand Down Expand Up @@ -199,7 +209,7 @@ void GlobOpt::ArraySrcOpt::TypeSpecIndex()
{
// If the optimization is unable to eliminate the bounds checks, we need to restore the original var sym.
Assert(originalIndexOpnd == nullptr);
originalIndexOpnd = instr->GetSrc1()->Copy(func)->AsRegOpnd();
originalIndexOpnd = instr->GetSrc1()->Copy(func);
globOpt->ToTypeSpecIndex(instr, instr->GetSrc1()->AsRegOpnd(), nullptr);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/GlobOptArrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GlobOpt::ArraySrcOpt
IR::IndirOpnd * baseOwnerIndir = nullptr;
IR::RegOpnd * baseOpnd = nullptr;
IR::Opnd * indexOpnd = nullptr;
IR::RegOpnd * originalIndexOpnd = nullptr;
IR::Opnd * originalIndexOpnd = nullptr;
bool isProfilableLdElem = false;
bool isProfilableStElem = false;
bool isLoad = false;
Expand Down

0 comments on commit e565611

Please sign in to comment.