Skip to content

Commit b7700e2

Browse files
committed
Don't add compensation code for array values in prepass. OS#17527968
1 parent 9796560 commit b7700e2

File tree

2 files changed

+63
-48
lines changed

2 files changed

+63
-48
lines changed

lib/Backend/GlobOptBlockData.cpp

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
10861086
// but in different syms, create a new sym and record that the array sym requires compensation. Compensation will be
10871087
// inserted later to initialize this new sym from all predecessors of the merged block.
10881088

1089-
StackSym *newHeadSegmentSym;
1089+
StackSym *newHeadSegmentSym = nullptr;
10901090
if(toDataValueInfo->HeadSegmentSym() && fromDataValueInfo->HeadSegmentSym())
10911091
{
10921092
if(toDataValueInfo->HeadSegmentSym() == fromDataValueInfo->HeadSegmentSym())
@@ -1095,27 +1095,26 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
10951095
}
10961096
else
10971097
{
1098-
Assert(!this->globOpt->IsLoopPrePass());
1099-
Assert(symsRequiringCompensation);
1100-
symsRequiringCompensation->Set(arraySym->m_id);
1101-
Assert(symsCreatedForMerge);
1102-
if(symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentSym()->m_id))
1098+
if (!this->globOpt->IsLoopPrePass())
11031099
{
1104-
newHeadSegmentSym = toDataValueInfo->HeadSegmentSym();
1105-
}
1106-
else
1107-
{
1108-
newHeadSegmentSym = StackSym::New(TyMachPtr, this->globOpt->func);
1109-
symsCreatedForMerge->Set(newHeadSegmentSym->m_id);
1100+
// Adding compensation code in the prepass won't help, as the symstores would again be different in the main pass.
1101+
Assert(symsRequiringCompensation);
1102+
symsRequiringCompensation->Set(arraySym->m_id);
1103+
Assert(symsCreatedForMerge);
1104+
if (symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentSym()->m_id))
1105+
{
1106+
newHeadSegmentSym = toDataValueInfo->HeadSegmentSym();
1107+
}
1108+
else
1109+
{
1110+
newHeadSegmentSym = StackSym::New(TyMachPtr, this->globOpt->func);
1111+
symsCreatedForMerge->Set(newHeadSegmentSym->m_id);
1112+
}
11101113
}
11111114
}
11121115
}
1113-
else
1114-
{
1115-
newHeadSegmentSym = nullptr;
1116-
}
11171116

1118-
StackSym *newHeadSegmentLengthSym;
1117+
StackSym *newHeadSegmentLengthSym = nullptr;
11191118
if(toDataValueInfo->HeadSegmentLengthSym() && fromDataValueInfo->HeadSegmentLengthSym())
11201119
{
11211120
if(toDataValueInfo->HeadSegmentLengthSym() == fromDataValueInfo->HeadSegmentLengthSym())
@@ -1124,27 +1123,25 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
11241123
}
11251124
else
11261125
{
1127-
Assert(!this->globOpt->IsLoopPrePass());
1128-
Assert(symsRequiringCompensation);
1129-
symsRequiringCompensation->Set(arraySym->m_id);
1130-
Assert(symsCreatedForMerge);
1131-
if(symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentLengthSym()->m_id))
1126+
if (!this->globOpt->IsLoopPrePass())
11321127
{
1133-
newHeadSegmentLengthSym = toDataValueInfo->HeadSegmentLengthSym();
1134-
}
1135-
else
1136-
{
1137-
newHeadSegmentLengthSym = StackSym::New(TyUint32, this->globOpt->func);
1138-
symsCreatedForMerge->Set(newHeadSegmentLengthSym->m_id);
1128+
Assert(symsRequiringCompensation);
1129+
symsRequiringCompensation->Set(arraySym->m_id);
1130+
Assert(symsCreatedForMerge);
1131+
if (symsCreatedForMerge->Test(toDataValueInfo->HeadSegmentLengthSym()->m_id))
1132+
{
1133+
newHeadSegmentLengthSym = toDataValueInfo->HeadSegmentLengthSym();
1134+
}
1135+
else
1136+
{
1137+
newHeadSegmentLengthSym = StackSym::New(TyUint32, this->globOpt->func);
1138+
symsCreatedForMerge->Set(newHeadSegmentLengthSym->m_id);
1139+
}
11391140
}
11401141
}
11411142
}
1142-
else
1143-
{
1144-
newHeadSegmentLengthSym = nullptr;
1145-
}
11461143

1147-
StackSym *newLengthSym;
1144+
StackSym *newLengthSym = nullptr;
11481145
if(toDataValueInfo->LengthSym() && fromDataValueInfo->LengthSym())
11491146
{
11501147
if(toDataValueInfo->LengthSym() == fromDataValueInfo->LengthSym())
@@ -1153,25 +1150,23 @@ ValueInfo *GlobOptBlockData::MergeArrayValueInfo(
11531150
}
11541151
else
11551152
{
1156-
Assert(!this->globOpt->IsLoopPrePass());
1157-
Assert(symsRequiringCompensation);
1158-
symsRequiringCompensation->Set(arraySym->m_id);
1159-
Assert(symsCreatedForMerge);
1160-
if(symsCreatedForMerge->Test(toDataValueInfo->LengthSym()->m_id))
1161-
{
1162-
newLengthSym = toDataValueInfo->LengthSym();
1163-
}
1164-
else
1153+
if (!this->globOpt->IsLoopPrePass())
11651154
{
1166-
newLengthSym = StackSym::New(TyUint32, this->globOpt->func);
1167-
symsCreatedForMerge->Set(newLengthSym->m_id);
1155+
Assert(symsRequiringCompensation);
1156+
symsRequiringCompensation->Set(arraySym->m_id);
1157+
Assert(symsCreatedForMerge);
1158+
if (symsCreatedForMerge->Test(toDataValueInfo->LengthSym()->m_id))
1159+
{
1160+
newLengthSym = toDataValueInfo->LengthSym();
1161+
}
1162+
else
1163+
{
1164+
newLengthSym = StackSym::New(TyUint32, this->globOpt->func);
1165+
symsCreatedForMerge->Set(newLengthSym->m_id);
1166+
}
11681167
}
11691168
}
11701169
}
1171-
else
1172-
{
1173-
newLengthSym = nullptr;
1174-
}
11751170

11761171
if(newHeadSegmentSym || newHeadSegmentLengthSym || newLengthSym)
11771172
{

test/Optimizer/Miscellaneous_MaxInterpret.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,3 +1071,23 @@ function test66() {
10711071
}
10721072
WScript.Echo("test66: " + test66());
10731073
WScript.Echo("test66: " + test66());
1074+
1075+
(function test67Runner(){
1076+
function test67(a,b,x){
1077+
var i = a[0];
1078+
var j = b[0];
1079+
var t = a;
1080+
for (var p = 0; p < x; p++) {
1081+
if (p > 2) {
1082+
t = b;
1083+
b = a;
1084+
}
1085+
}
1086+
}
1087+
1088+
var arr1 = [1,2];
1089+
var arr2 = [3,4];
1090+
var x = 1;
1091+
test67(arr1, arr2, x);
1092+
test67(arr1, arr2, x)
1093+
})();

0 commit comments

Comments
 (0)