Skip to content

Commit ea11fc0

Browse files
committed
A couple of fixes with inline args opt and stack args opt
1 parent 72302b4 commit ea11fc0

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

lib/Backend/BackwardPass.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8033,11 +8033,12 @@ BackwardPass::ProcessInlineeStart(IR::Instr* inlineeStart)
80338033

80348034
if (!inlineeStart->m_func->m_hasInlineArgsOpt)
80358035
{
8036-
PHASE_PRINT_TESTTRACE(Js::InlineArgsOptPhase, func, _u("%s[%d]: Skipping inline args optimization: %s[%d] HasCalls: %s 'arguments' access: %s Can do inlinee args opt: %s\n"),
8036+
PHASE_PRINT_TESTTRACE(Js::InlineArgsOptPhase, func, _u("%s[%d]: Skipping inline args optimization: %s[%d] HasCalls: %s, 'arguments' access: %s, stackArgs enabled: %s, Can do inlinee args opt: %s\n"),
80378037
func->GetJITFunctionBody()->GetDisplayName(), func->GetJITFunctionBody()->GetFunctionNumber(),
80388038
inlineeStart->m_func->GetJITFunctionBody()->GetDisplayName(), inlineeStart->m_func->GetJITFunctionBody()->GetFunctionNumber(),
80398039
IsTrueOrFalse(inlineeStart->m_func->GetHasCalls()),
80408040
IsTrueOrFalse(inlineeStart->m_func->GetHasUnoptimizedArgumentsAccess()),
8041+
IsTrueOrFalse(inlineeStart->m_func->IsStackArgsEnabled()),
80418042
IsTrueOrFalse(inlineeStart->m_func->m_canDoInlineArgsOpt));
80428043
return false;
80438044
}
@@ -8115,6 +8116,11 @@ BackwardPass::ProcessInlineeEnd(IR::Instr* instr)
81158116
}
81168117
else if (this->tag == Js::DeadStorePhase)
81178118
{
8119+
if (instr->m_func->GetJITFunctionBody()->UsesArgumentsObject() && !instr->m_func->IsStackArgsEnabled())
8120+
{
8121+
instr->m_func->DisableCanDoInlineArgOpt();
8122+
}
8123+
81188124
if (instr->m_func->m_hasInlineArgsOpt)
81198125
{
81208126
Assert(instr->m_func->frameInfo);

lib/Backend/Func.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Func::Func(JitArenaAllocator *alloc, JITTimeWorkItem * workItem,
6767
m_hasInlineArgsOpt(false),
6868
m_canDoInlineArgsOpt(true),
6969
unoptimizableArgumentsObjReference(0),
70+
unoptimizableArgumentsObjReferenceInInlinees(0),
7071
m_doFastPaths(false),
7172
hasBailout(false),
7273
firstIRTemp(0),

lib/Backend/Func.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
726726
StackSym * tempSymBool;
727727
uint32 loopCount;
728728
uint32 unoptimizableArgumentsObjReference;
729+
uint32 unoptimizableArgumentsObjReferenceInInlinees;
729730
Js::ProfileId callSiteIdInParentFunc;
730731
InlineeFrameInfo* cachedInlineeFrameInfo;
731732
bool m_hasCalls: 1; // This is more accurate compared to m_isLeaf
@@ -855,6 +856,7 @@ static const unsigned __int64 c_debugFillPattern8 = 0xcececececececece;
855856
{
856857
curFunc->m_canDoInlineArgsOpt = false;
857858
curFunc->m_hasInlineArgsOpt = false;
859+
curFunc->frameInfo = nullptr;
858860
curFunc = curFunc->GetParentFunc();
859861
}
860862
}

lib/Backend/GlobOptBailOut.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,12 @@ GlobOpt::CaptureByteCodeSymUses(IR::Instr * instr)
482482
void
483483
GlobOpt::ProcessInlineeEnd(IR::Instr* instr)
484484
{
485-
if (!PHASE_OFF(Js::StackArgLenConstOptPhase, instr->m_func) && instr->m_func->IsStackArgsEnabled()
486-
&& instr->m_func->hasArgLenAndConstOpt && instr->m_func->unoptimizableArgumentsObjReference == 0)
485+
if (!PHASE_OFF(Js::StackArgLenConstOptPhase, instr->m_func) &&
486+
(!instr->m_func->GetJITFunctionBody()->UsesArgumentsObject() || instr->m_func->IsStackArgsEnabled())
487+
&& instr->m_func->unoptimizableArgumentsObjReference == 0 && instr->m_func->unoptimizableArgumentsObjReferenceInInlinees == 0)
487488
{
488489
instr->m_func->hasUnoptimizedArgumentsAccess = false;
489-
if (DoInlineArgsOpt(instr->m_func))
490+
if (!instr->m_func->m_hasInlineArgsOpt && DoInlineArgsOpt(instr->m_func))
490491
{
491492
instr->m_func->m_hasInlineArgsOpt = true;
492493
Assert(instr->m_func->cachedInlineeFrameInfo);
@@ -502,6 +503,8 @@ GlobOpt::ProcessInlineeEnd(IR::Instr* instr)
502503

503504
Assert(this->currentBlock->globOptData.inlinedArgOutSize >= instr->GetArgOutSize(/*getInterpreterArgOutCount*/ false));
504505
this->currentBlock->globOptData.inlinedArgOutSize -= instr->GetArgOutSize(/*getInterpreterArgOutCount*/ false);
506+
507+
instr->m_func->GetParentFunc()->unoptimizableArgumentsObjReferenceInInlinees += instr->m_func->unoptimizableArgumentsObjReference;
505508
}
506509

507510
void

test/Optimizer/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,11 @@
15001500
<compile-flags>-off:usefixeddataprops -off:objtypespec</compile-flags>
15011501
</default>
15021502
</test>
1503+
<test>
1504+
<default>
1505+
<files>test152.js</files>
1506+
</default>
1507+
</test>
15031508
<test>
15041509
<default>
15051510
<files>IsIn_ArrayNoMissingValues.js</files>

test/Optimizer/test152.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function bar()
7+
{
8+
return arguments.length + arguments[0];
9+
}
10+
11+
function foo(a)
12+
{
13+
return bar(a) + arguments;
14+
}
15+
16+
foo(1)
17+
foo(1)
18+
foo(1)
19+
20+
21+
function test4(a)
22+
{
23+
return arguments.length + arguments[0];
24+
}
25+
26+
function test3(a)
27+
{
28+
return test4(a);
29+
}
30+
31+
function test2(a)
32+
{
33+
return test3(a) + arguments.length;
34+
}
35+
36+
function test1(a)
37+
{
38+
return test2(a)
39+
}
40+
test1(1)
41+
test1(1)
42+
test1(1)
43+
44+
print("passed")

0 commit comments

Comments
 (0)