Skip to content

Commit 008acc8

Browse files
Fix issue with unsigned compare peep in dead code.
The unsigned compare peep optimization, after being changed to have the bytecodeuses instruction emitted after the compare instead of before it, had issues with lowering of code hidden behind a bailonnoprofile, in that it would have conflicts on lifetimes due to the loss of atomicity of the bytecodereg use and generation of the compare. This patch attempts to restore that by aggregating the bytecodeuse information for a single instruction into once place.
1 parent 54ed1e6 commit 008acc8

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

lib/Backend/GlobOptBailOut.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,43 @@ GlobOpt::ConvertToByteCodeUses(IR::Instr * instr)
10851085
this->CaptureByteCodeSymUses(instr);
10861086
IR::ByteCodeUsesInstr * byteCodeUsesInstr = this->InsertByteCodeUses(instr, true);
10871087
instr->Remove();
1088+
// If possible, we want to aggregate with subsequent ByteCodeUses Instructions, so
1089+
// that we can do some optimizations in other places where we can simplify args in
1090+
// a compare, but still need to generate them for bailouts. Without this, we cause
1091+
// problems because we end up with an instruction losing atomicity in terms of its
1092+
// bytecode use and generation lifetimes.
1093+
if (byteCodeUsesInstr &&
1094+
byteCodeUsesInstr->m_next &&
1095+
byteCodeUsesInstr->m_next->m_opcode == Js::OpCode::ByteCodeUses &&
1096+
byteCodeUsesInstr->GetByteCodeOffset() == byteCodeUsesInstr->m_next->GetByteCodeOffset()
1097+
)
1098+
{
1099+
IR::ByteCodeUsesInstr * nextinstr = byteCodeUsesInstr->m_next->AsByteCodeUsesInstr();
1100+
if (nextinstr->GetDst() == nullptr)
1101+
{
1102+
// We move all of the uses of the next bytecodeuses instruction into this one. The
1103+
// instruction is notably not removed or repurposed; unfortunately, at this point,
1104+
// doing either would be somewhat complex. Removing the instruction breaks some of
1105+
// the assumptions made in other code (notably RemoveCodeAfterNoFallthroughInstr),
1106+
// and repurposing it by removing the newly-added byteCodeUsesInstr requires us to
1107+
// be able to handle transferring the Dst reg in a couple more cases (like if it's
1108+
// single-def).
1109+
if (nextinstr->byteCodeUpwardExposedUsed)
1110+
{
1111+
if (byteCodeUsesInstr->byteCodeUpwardExposedUsed)
1112+
{
1113+
byteCodeUsesInstr->byteCodeUpwardExposedUsed->Or(nextinstr->byteCodeUpwardExposedUsed);
1114+
JitAdelete(nextinstr->byteCodeUpwardExposedUsed->GetAllocator(), nextinstr->byteCodeUpwardExposedUsed);
1115+
nextinstr->byteCodeUpwardExposedUsed = nullptr;
1116+
}
1117+
else
1118+
{
1119+
byteCodeUsesInstr->byteCodeUpwardExposedUsed = nextinstr->byteCodeUpwardExposedUsed;
1120+
nextinstr->byteCodeUpwardExposedUsed = nullptr;
1121+
}
1122+
}
1123+
}
1124+
}
10881125
return byteCodeUsesInstr;
10891126
}
10901127

test/Bugs/bug9080773_2.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 protoObj1 = {};
7+
for (var __loopSecondaryVar1000_0 = 10; protoObj1.length; protoObj1) {
8+
var v4 = prop0 >>> 0 < 0;
9+
}
10+
}
11+
test0();
12+
test0();
13+
test0();
14+
15+
WScript.Echo("PASSED");

test/Bugs/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@
290290
<compile-flags>-maxinterpretcount:1 -off:simplejit</compile-flags>
291291
</default>
292292
</test>
293+
<test>
294+
<default>
295+
<files>bug9080773_2.js</files>
296+
<compile-flags>-maxinterpretcount:1 -maxsimplejitruncount:1</compile-flags>
297+
</default>
298+
</test>
293299
<test>
294300
<default>
295301
<files>b208_asmjs.js</files>

0 commit comments

Comments
 (0)