Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,37 @@ ValueNum ValueNumStore::VNForFunc(var_types typ, VNFunc func, ValueNum arg0VN)
{
*resultVN = VNForIntCon(knownSize);
}

// Case 4: ARR_LENGTH(new T[(long)size]) -> size
VNFuncApp newArrFuncApp;
if (GetVNFunc(arg0VN, &newArrFuncApp) && (newArrFuncApp.m_func == VNF_JitNewArr))
{
ValueNum actualSizeVN = newArrFuncApp.m_args[1];
var_types actualSizeVNType = TypeOfVN(actualSizeVN);

// JitNewArr's size argument (args[1]) is typically upcasted to TYP_LONG via VNF_Cast.
if (actualSizeVNType == TYP_LONG)
{
VNFuncApp castFuncApp;
if (GetVNFunc(actualSizeVN, &castFuncApp) && (castFuncApp.m_func == VNF_Cast))
{
var_types castToType;
bool srcIsUnsigned;
GetCastOperFromVN(castFuncApp.m_args[1], &castToType, &srcIsUnsigned);

// Make sure we have exactly (TYP_LONG)myInt32 cast:
if (!srcIsUnsigned && (castToType == TYP_LONG) && TypeOfVN(castFuncApp.m_args[0]) == TYP_INT)
{
// If that is the case, return the original size argument
*resultVN = castFuncApp.m_args[0];
}
}
}
else if (actualSizeVNType == TYP_INT)
{
*resultVN = actualSizeVN;
}
}
}

// Try to perform constant-folding.
Expand Down
Loading