Skip to content

Commit ef9955f

Browse files
committed
When searching for new bytecode instr for a post-op bailout, follow unconditional branches.
1 parent 16de442 commit ef9955f

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

lib/Backend/GlobOptBailOut.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,24 +1372,10 @@ GlobOpt::MayNeedBailOnImplicitCall(IR::Instr const * instr, Value const * src1Va
13721372
void
13731373
GlobOpt::GenerateBailAfterOperation(IR::Instr * *const pInstr, IR::BailOutKind kind)
13741374
{
1375-
Assert(pInstr);
1375+
Assert(pInstr && *pInstr);
13761376

13771377
IR::Instr* instr = *pInstr;
1378-
Assert(instr);
1379-
1380-
IR::Instr * nextInstr = instr->GetNextRealInstrOrLabel();
1381-
uint32 currentOffset = instr->GetByteCodeOffset();
1382-
while (nextInstr->GetByteCodeOffset() == Js::Constants::NoByteCodeOffset ||
1383-
nextInstr->GetByteCodeOffset() == currentOffset)
1384-
{
1385-
nextInstr = nextInstr->GetNextRealInstrOrLabel();
1386-
}
1387-
// This can happen due to break block removal
1388-
while (nextInstr->GetByteCodeOffset() == Js::Constants::NoByteCodeOffset ||
1389-
nextInstr->GetByteCodeOffset() < currentOffset)
1390-
{
1391-
nextInstr = nextInstr->GetNextRealInstrOrLabel();
1392-
}
1378+
IR::Instr * nextInstr = instr->GetNextByteCodeInstr();
13931379
IR::Instr * bailOutInstr = instr->ConvertToBailOutInstr(nextInstr, kind);
13941380
if (this->currentBlock->GetLastInstr() == instr)
13951381
{

lib/Backend/IR.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,35 @@ Instr::GetNextBranchOrLabel() const
27042704
return instr;
27052705
}
27062706

2707+
IR::Instr *
2708+
Instr::GetNextByteCodeInstr() const
2709+
{
2710+
IR::Instr * nextInstr = GetNextRealInstrOrLabel();
2711+
uint32 currentOffset = GetByteCodeOffset();
2712+
const auto getNext = [](IR::Instr* nextInstr) -> IR::Instr*
2713+
{
2714+
if (nextInstr->IsBranchInstr())
2715+
{
2716+
IR::BranchInstr* branchInstr = nextInstr->AsBranchInstr();
2717+
AssertMsg(branchInstr->IsUnconditional(), "We can't know which branch to take on a conditionnal branch");
2718+
return branchInstr->GetTarget();
2719+
}
2720+
return nextInstr->GetNextRealInstrOrLabel();
2721+
};
2722+
while (nextInstr->GetByteCodeOffset() == Js::Constants::NoByteCodeOffset ||
2723+
nextInstr->GetByteCodeOffset() == currentOffset)
2724+
{
2725+
nextInstr = getNext(nextInstr);
2726+
}
2727+
// This can happen due to break block removal
2728+
while (nextInstr->GetByteCodeOffset() == Js::Constants::NoByteCodeOffset ||
2729+
nextInstr->GetByteCodeOffset() < currentOffset)
2730+
{
2731+
nextInstr = getNext(nextInstr);
2732+
}
2733+
return nextInstr;
2734+
}
2735+
27072736
///----------------------------------------------------------------------------
27082737
///
27092738
/// Instr::GetPrevRealInstr

lib/Backend/IR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class Instr
288288
IR::Instr * GetNextRealInstr() const;
289289
IR::Instr * GetNextRealInstrOrLabel() const;
290290
IR::Instr * GetNextBranchOrLabel() const;
291+
IR::Instr * GetNextByteCodeInstr() const;
291292
IR::Instr * GetPrevRealInstr() const;
292293
IR::Instr * GetPrevRealInstrOrLabel() const;
293294
IR::LabelInstr *GetPrevLabelInstr() const;

0 commit comments

Comments
 (0)