Skip to content

Commit 6bd18b7

Browse files
committed
enable IsIn optimization for addrOpnds
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) ...```.
1 parent 1f0614f commit 6bd18b7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/Backend/GlobOptArrays.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ bool GlobOpt::ArraySrcOpt::CheckOpCode()
151151
return false;
152152
}
153153

154+
if (instr->GetSrc1()->IsAddrOpnd())
155+
{
156+
const Js::Var val = instr->GetSrc1()->AsAddrOpnd()->m_address;
157+
if (Js::TaggedInt::Is(val))
158+
{
159+
originalIndexOpnd = instr->UnlinkSrc1();
160+
instr->SetSrc1(IR::IntConstOpnd::New(Js::TaggedInt::ToInt32(val), TyInt32, instr->m_func));
161+
}
162+
}
163+
154164
if (!instr->GetSrc1()->IsRegOpnd() && !instr->GetSrc1()->IsIntConstOpnd())
155165
{
156166
return false;
@@ -199,7 +209,7 @@ void GlobOpt::ArraySrcOpt::TypeSpecIndex()
199209
{
200210
// If the optimization is unable to eliminate the bounds checks, we need to restore the original var sym.
201211
Assert(originalIndexOpnd == nullptr);
202-
originalIndexOpnd = instr->GetSrc1()->Copy(func)->AsRegOpnd();
212+
originalIndexOpnd = instr->GetSrc1()->Copy(func);
203213
globOpt->ToTypeSpecIndex(instr, instr->GetSrc1()->AsRegOpnd(), nullptr);
204214
}
205215
}

lib/Backend/GlobOptArrays.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class GlobOpt::ArraySrcOpt
5252
IR::IndirOpnd * baseOwnerIndir = nullptr;
5353
IR::RegOpnd * baseOpnd = nullptr;
5454
IR::Opnd * indexOpnd = nullptr;
55-
IR::RegOpnd * originalIndexOpnd = nullptr;
55+
IR::Opnd * originalIndexOpnd = nullptr;
5656
bool isProfilableLdElem = false;
5757
bool isProfilableStElem = false;
5858
bool isLoad = false;

0 commit comments

Comments
 (0)