Skip to content

Commit 2d76ace

Browse files
author
Meghana Gupta
committed
[MERGE #5483 @meg-gupta] Add empty ByteCodeUses instr with correct bytecode offset for for InlineeEnd cases in path dependent branch folding
Merge pull request #5483 from meg-gupta:pathdepbug Fixes OS#17678270
2 parents 7aa8981 + dd40125 commit 2d76ace

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lib/Backend/FlowGraph.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4854,13 +4854,15 @@ BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
48544854
if (branchTarget != this->GetLastInstr()->GetNextRealInstrOrLabel())
48554855
{
48564856
IR::Instr* lastInstr = this->GetLastInstr();
4857+
// We add an empty ByteCodeUses with correct bytecodeoffset, for correct info on a post-op bailout of the previous instr
4858+
IR::Instr* emptyByteCodeUse = IR::ByteCodeUsesInstr::New(lastInstr->m_func, lastInstr->GetByteCodeOffset());
4859+
lastInstr->InsertAfter(emptyByteCodeUse);
48574860
IR::BranchInstr * newBranch = IR::BranchInstr::New(Js::OpCode::Br, branchTarget, branchTarget->m_func);
4858-
newBranch->SetByteCodeOffset(lastInstr);
48594861
if (lastInstr->IsBranchInstr())
48604862
{
48614863
globOpt->ConvertToByteCodeUses(lastInstr);
48624864
}
4863-
this->GetLastInstr()->InsertAfter(newBranch);
4865+
emptyByteCodeUse->InsertAfter(newBranch);
48644866
globOpt->func->m_fg->AddEdge(this, branchTarget->GetBasicBlock());
48654867
this->IncrementDataUseCount();
48664868
}

test/Optimizer/pathdepbug.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
function test0() {
6+
var arrObj0 = {};
7+
var func0 = function () {
8+
for (; arrObj0.prop1; ) {
9+
__loopSecondaryVar4_0 = 2;
10+
break;
11+
}
12+
return 1;
13+
};
14+
var func2 = function () {
15+
var __loopvar4 = 8;
16+
for (;;) {
17+
if (__loopvar4 > 8) {
18+
break;
19+
}
20+
__loopvar4++;
21+
func0() >= 0 ? func0() : 0;
22+
}
23+
};
24+
return func2(func2());
25+
}
26+
test0();
27+
test0();
28+
print("Passed\n");

test/Optimizer/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,4 +1562,10 @@
15621562
<compile-flags>-maxinterpretcount:1 -maxsimplejitruncount:1 -loopinterpretcount:1 -oopjit- -bgjit-</compile-flags>
15631563
</default>
15641564
</test>
1565+
<test>
1566+
<default>
1567+
<files>pathdepbug.js</files>
1568+
<compile-flags>-maxinterpretcount:1 -maxsimplejitruncount:1 -off:aggressiveinttypespec</compile-flags>
1569+
</default>
1570+
</test>
15651571
</regress-exe>

0 commit comments

Comments
 (0)