Skip to content

Commit

Permalink
Don't add compensation code for array values in prepass. OS#17527968
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatd committed Jul 26, 2018
1 parent 9796560 commit b7700e2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 48 deletions.
91 changes: 43 additions & 48 deletions lib/Backend/GlobOptBlockData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
// but in different syms, create a new sym and record that the array sym requires compensation. Compensation will be
// inserted later to initialize this new sym from all predecessors of the merged block.

StackSym *newHeadSegmentSym;
StackSym *newHeadSegmentSym = nullptr;
if(toDataValueInfo->HeadSegmentSym() && fromDataValueInfo->HeadSegmentSym())
{
if(toDataValueInfo->HeadSegmentSym() == fromDataValueInfo->HeadSegmentSym())
Expand All @@ -1095,27 +1095,26 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
}
else
{
Assert(!this->globOpt->IsLoopPrePass());
Assert(symsRequiringCompensation);
symsRequiringCompensation->Set(arraySym->m_id);
Assert(symsCreatedForMerge);
if(symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentSym()->m_id))
if (!this->globOpt->IsLoopPrePass())
{
newHeadSegmentSym = toDataValueInfo->HeadSegmentSym();
}
else
{
newHeadSegmentSym = StackSym::New(TyMachPtr, this->globOpt->func);
symsCreatedForMerge->Set(newHeadSegmentSym->m_id);
// Adding compensation code in the prepass won't help, as the symstores would again be different in the main pass.
Assert(symsRequiringCompensation);
symsRequiringCompensation->Set(arraySym->m_id);
Assert(symsCreatedForMerge);
if (symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentSym()->m_id))
{
newHeadSegmentSym = toDataValueInfo->HeadSegmentSym();
}
else
{
newHeadSegmentSym = StackSym::New(TyMachPtr, this->globOpt->func);
symsCreatedForMerge->Set(newHeadSegmentSym->m_id);
}
}
}
}
else
{
newHeadSegmentSym = nullptr;
}

StackSym *newHeadSegmentLengthSym;
StackSym *newHeadSegmentLengthSym = nullptr;
if(toDataValueInfo->HeadSegmentLengthSym() && fromDataValueInfo->HeadSegmentLengthSym())
{
if(toDataValueInfo->HeadSegmentLengthSym() == fromDataValueInfo->HeadSegmentLengthSym())
Expand All @@ -1124,27 +1123,25 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
}
else
{
Assert(!this->globOpt->IsLoopPrePass());
Assert(symsRequiringCompensation);
symsRequiringCompensation->Set(arraySym->m_id);
Assert(symsCreatedForMerge);
if(symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentLengthSym()->m_id))
if (!this->globOpt->IsLoopPrePass())
{
newHeadSegmentLengthSym = toDataValueInfo->HeadSegmentLengthSym();
}
else
{
newHeadSegmentLengthSym = StackSym::New(TyUint32, this->globOpt->func);
symsCreatedForMerge->Set(newHeadSegmentLengthSym->m_id);
Assert(symsRequiringCompensation);
symsRequiringCompensation->Set(arraySym->m_id);
Assert(symsCreatedForMerge);
if (symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentLengthSym()->m_id))
{
newHeadSegmentLengthSym = toDataValueInfo->HeadSegmentLengthSym();
}
else
{
newHeadSegmentLengthSym = StackSym::New(TyUint32, this->globOpt->func);
symsCreatedForMerge->Set(newHeadSegmentLengthSym->m_id);
}
}
}
}
else
{
newHeadSegmentLengthSym = nullptr;
}

StackSym *newLengthSym;
StackSym *newLengthSym = nullptr;
if(toDataValueInfo->LengthSym() && fromDataValueInfo->LengthSym())
{
if(toDataValueInfo->LengthSym() == fromDataValueInfo->LengthSym())
Expand All @@ -1153,25 +1150,23 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
}
else
{
Assert(!this->globOpt->IsLoopPrePass());
Assert(symsRequiringCompensation);
symsRequiringCompensation->Set(arraySym->m_id);
Assert(symsCreatedForMerge);
if(symsCreatedForMerge->Test(toDataValueInfo->LengthSym()->m_id))
{
newLengthSym = toDataValueInfo->LengthSym();
}
else
if (!this->globOpt->IsLoopPrePass())
{
newLengthSym = StackSym::New(TyUint32, this->globOpt->func);
symsCreatedForMerge->Set(newLengthSym->m_id);
Assert(symsRequiringCompensation);
symsRequiringCompensation->Set(arraySym->m_id);
Assert(symsCreatedForMerge);
if (symsCreatedForMerge->Test(toDataValueInfo->LengthSym()->m_id))
{
newLengthSym = toDataValueInfo->LengthSym();
}
else
{
newLengthSym = StackSym::New(TyUint32, this->globOpt->func);
symsCreatedForMerge->Set(newLengthSym->m_id);
}
}
}
}
else
{
newLengthSym = nullptr;
}

if(newHeadSegmentSym || newHeadSegmentLengthSym || newLengthSym)
{
Expand Down
20 changes: 20 additions & 0 deletions test/Optimizer/Miscellaneous_MaxInterpret.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,3 +1071,23 @@ function test66() {
}
WScript.Echo("test66: " + test66());
WScript.Echo("test66: " + test66());

(function test67Runner(){
function test67(a,b,x){
var i = a[0];
var j = b[0];
var t = a;
for (var p = 0; p < x; p++) {
if (p > 2) {
t = b;
b = a;
}
}
}

var arr1 = [1,2];
var arr2 = [3,4];
var x = 1;
test67(arr1, arr2, x);
test67(arr1, arr2, x)
})();

0 comments on commit b7700e2

Please sign in to comment.