From b7700e2074652d3e60278a2b60fecac10ef0fdad Mon Sep 17 00:00:00 2001 From: Rajat Dua Date: Thu, 26 Jul 2018 11:25:08 -0700 Subject: [PATCH] Don't add compensation code for array values in prepass. OS#17527968 --- lib/Backend/GlobOptBlockData.cpp | 91 +++++++++----------- test/Optimizer/Miscellaneous_MaxInterpret.js | 20 +++++ 2 files changed, 63 insertions(+), 48 deletions(-) diff --git a/lib/Backend/GlobOptBlockData.cpp b/lib/Backend/GlobOptBlockData.cpp index 19bcc514d51..31ad9566b1a 100644 --- a/lib/Backend/GlobOptBlockData.cpp +++ b/lib/Backend/GlobOptBlockData.cpp @@ -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()) @@ -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()) @@ -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()) @@ -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) { diff --git a/test/Optimizer/Miscellaneous_MaxInterpret.js b/test/Optimizer/Miscellaneous_MaxInterpret.js index 0936cc99df0..e60e7e3bf0b 100644 --- a/test/Optimizer/Miscellaneous_MaxInterpret.js +++ b/test/Optimizer/Miscellaneous_MaxInterpret.js @@ -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) +})(); \ No newline at end of file