Skip to content

Commit a5b260e

Browse files
committed
On 32 bits platform, we shouldn't do a fast path for constructors with arguments we know can't be a tagged int.
1 parent e381509 commit a5b260e

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

lib/Backend/Lower.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,12 +3687,12 @@ BOOL Lowerer::IsSmallObject(uint32 length)
36873687
return HeapInfo::IsSmallObject(HeapInfo::GetAlignedSizeNoCheck(allocSize));
36883688
}
36893689

3690-
void
3690+
bool
36913691
Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length)
36923692
{
36933693
if (PHASE_OFF(Js::ArrayCtorFastPathPhase, m_func) || CONFIG_FLAG(ForceES5Array))
36943694
{
3695-
return;
3695+
return false;
36963696
}
36973697

36983698
Func * func = this->m_func;
@@ -3707,7 +3707,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37073707
{
37083708
if (!IsSmallObject<Js::JavascriptNativeIntArray>(length))
37093709
{
3710-
return;
3710+
return false;
37113711
}
37123712
GenerateArrayInfoIsNativeIntArrayTest(instr, arrayInfo, arrayInfoAddr, helperLabel);
37133713
Assert(Js::JavascriptNativeIntArray::GetOffsetOfArrayFlags() + sizeof(uint16) == Js::JavascriptNativeIntArray::GetOffsetOfArrayCallSiteIndex());
@@ -3725,7 +3725,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37253725
{
37263726
if (!IsSmallObject<Js::JavascriptNativeFloatArray>(length))
37273727
{
3728-
return;
3728+
return false;
37293729
}
37303730
GenerateArrayInfoIsNativeFloatAndNotIntArrayTest(instr, arrayInfo, arrayInfoAddr, helperLabel);
37313731
Assert(Js::JavascriptNativeFloatArray::GetOffsetOfArrayFlags() + sizeof(uint16) == Js::JavascriptNativeFloatArray::GetOffsetOfArrayCallSiteIndex());
@@ -3749,7 +3749,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37493749
{
37503750
if (!IsSmallObject<Js::JavascriptArray>(length))
37513751
{
3752-
return;
3752+
return false;
37533753
}
37543754
uint const offsetStart = sizeof(Js::SparseArraySegmentBase);
37553755
headOpnd = GenerateArrayLiteralsAlloc<Js::JavascriptArray>(instr, &size, arrayInfo, &isZeroed);
@@ -3769,6 +3769,7 @@ Lowerer::GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteI
37693769
instr->InsertBefore(helperLabel);
37703770

37713771
instr->InsertAfter(doneLabel);
3772+
return true;
37723773
}
37733774

37743775
void
@@ -4030,12 +4031,12 @@ Lowerer::GenerateArrayAlloc(IR::Instr *instr, IR::Opnd * arrayLenOpnd, Js::Array
40304031
}
40314032

40324033

4033-
void
4034+
bool
40344035
Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs)
40354036
{
40364037
if (PHASE_OFF(Js::ArrayCtorFastPathPhase, m_func))
40374038
{
4038-
return;
4039+
return false;
40394040
}
40404041

40414042
Func * func = this->m_func;
@@ -4095,17 +4096,18 @@ Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSi
40954096
// Skip pass the helper call
40964097
InsertBranch(Js::OpCode::Br, labelDone, instr);
40974098
instr->InsertBefore(helperLabel);
4099+
return true;
40984100
}
40994101

41004102

41014103
template <typename ArrayType>
4102-
void
4104+
bool
41034105
Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel,
41044106
IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef)
41054107
{
41064108
if (PHASE_OFF(Js::ArrayCtorFastPathPhase, m_func))
41074109
{
4108-
return;
4110+
return false;
41094111
}
41104112

41114113
Func * func = this->m_func;
@@ -4199,6 +4201,7 @@ Lowerer::GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSi
41994201

42004202
Lowerer::InsertBranch(Js::OpCode::Br, labelDone, instr);
42014203
instr->InsertBefore(helperLabel);
4204+
return true;
42024205
}
42034206

42044207
void
@@ -5271,26 +5274,29 @@ Lowerer::LowerNewScObjArray(IR::Instr *newObjInstr)
52715274
AssertMsg(linkSym->IsArgSlotSym(), "Not an argSlot symbol...");
52725275
linkOpnd = argInstr->GetSrc2();
52735276

5274-
bool emittedFastPath = true;
5277+
bool emittedFastPath = false;
52755278
// 2a. If 1st parameter is a variable, emit fast path with checks
52765279
if (opndOfArrayCtor->IsRegOpnd())
52775280
{
5278-
// 3. GenerateFastPath
5279-
if (arrayInfo && arrayInfo->IsNativeIntArray())
5280-
{
5281-
GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeIntArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5282-
Js::JavascriptNativeIntArray::GetOffsetOfArrayCallSiteIndex(),
5283-
Js::JavascriptNativeIntArray::GetOffsetOfWeakFuncRef());
5284-
}
5285-
else if (arrayInfo && arrayInfo->IsNativeFloatArray())
5281+
if (!opndOfArrayCtor->AsRegOpnd()->IsNotInt())
52865282
{
5287-
GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeFloatArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5288-
Js::JavascriptNativeFloatArray::GetOffsetOfArrayCallSiteIndex(),
5289-
Js::JavascriptNativeFloatArray::GetOffsetOfWeakFuncRef());
5290-
}
5291-
else
5292-
{
5293-
GenerateProfiledNewScObjArrayFastPath<Js::JavascriptArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor, 0, 0);
5283+
// 3. GenerateFastPath
5284+
if (arrayInfo && arrayInfo->IsNativeIntArray())
5285+
{
5286+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeIntArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5287+
Js::JavascriptNativeIntArray::GetOffsetOfArrayCallSiteIndex(),
5288+
Js::JavascriptNativeIntArray::GetOffsetOfWeakFuncRef());
5289+
}
5290+
else if (arrayInfo && arrayInfo->IsNativeFloatArray())
5291+
{
5292+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath<Js::JavascriptNativeFloatArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor,
5293+
Js::JavascriptNativeFloatArray::GetOffsetOfArrayCallSiteIndex(),
5294+
Js::JavascriptNativeFloatArray::GetOffsetOfWeakFuncRef());
5295+
}
5296+
else
5297+
{
5298+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath<Js::JavascriptArray>(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, helperLabel, labelDone, opndOfArrayCtor, 0, 0);
5299+
}
52945300
}
52955301
}
52965302
// 2b. If 1st parameter is a constant, it is in range 0 and upperBoundValue (inclusive)
@@ -5299,11 +5305,7 @@ Lowerer::LowerNewScObjArray(IR::Instr *newObjInstr)
52995305
int32 length = linkSym->GetIntConstValue();
53005306
if (length >= 0 && length <= upperBoundValue)
53015307
{
5302-
GenerateProfiledNewScObjArrayFastPath(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, (uint32)length, labelDone, false);
5303-
}
5304-
else
5305-
{
5306-
emittedFastPath = false;
5308+
emittedFastPath = GenerateProfiledNewScObjArrayFastPath(newObjInstr, arrayInfo, arrayInfoAddr, weakFuncRef, (uint32)length, labelDone, false);
53075309
}
53085310
}
53095311
// Since we emitted fast path above, move the startCall/argOut instruction right before helper

lib/Backend/Lower.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,11 @@ class Lowerer
667667
template <typename ArrayType>
668668
IR::RegOpnd * GenerateArrayAlloc(IR::Instr *instr, IR::Opnd * sizeOpnd, Js::ArrayCallSiteInfo * arrayInfo);
669669

670-
void GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs);
670+
bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length, IR::LabelInstr* labelDone, bool isNoArgs);
671671

672672
template <typename ArrayType>
673-
void GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel, IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef);
674-
void GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length);
673+
bool GenerateProfiledNewScObjArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, IR::LabelInstr* helperLabel, IR::LabelInstr* labelDone, IR::Opnd* lengthOpnd, uint32 offsetOfCallSiteIndex, uint32 offsetOfWeakFuncRef);
674+
bool GenerateProfiledNewScArrayFastPath(IR::Instr *instr, Js::ArrayCallSiteInfo * arrayInfo, intptr_t arrayInfoAddr, intptr_t weakFuncRef, uint32 length);
675675

676676
void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, int32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);
677677
void GenerateMemInit(IR::RegOpnd * opnd, int32 offset, uint32 value, IR::Instr * insertBeforeInstr, bool isZeroed = false);

test/Array/constructor_fastpath.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//-------------------------------------------------------------------------------------------------------
55

66
function makeArray() {
7-
return [new Array(true), new Array("some string")];
7+
return [new Array(true), new Array("some string"), new Array(1075133691)];
88
}
99

1010
for (let i = 0; i < 100; ++i) {

0 commit comments

Comments
 (0)