Skip to content

Commit 873d682

Browse files
committed
Move importervectorization to a late phase
1 parent ecaa1c5 commit 873d682

10 files changed

Lines changed: 370 additions & 846 deletions

File tree

src/coreclr/jit/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ set( JIT_SOURCES
142142
ifconversion.cpp
143143
importer.cpp
144144
importercalls.cpp
145-
importervectorization.cpp
146145
indirectcalltransformer.cpp
147146
inductionvariableopts.cpp
148147
inline.cpp

src/coreclr/jit/assertionprop.cpp

Lines changed: 301 additions & 35 deletions
Large diffs are not rendered by default.

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3960,6 +3960,7 @@ class Compiler
39603960
//-------------------------------------------------------------------------
39613961

39623962
GenTree* gtFoldExpr(GenTree* tree);
3963+
GenTree* gtFoldExprConstChain(GenTree* tree, int maxDepth = 10);
39633964
GenTree* gtFoldExprConst(GenTree* tree);
39643965

39653966
GenTree* gtFoldExprUnary(GenTreeUnOp* tree);
@@ -5184,32 +5185,6 @@ class Compiler
51845185
GenTree* impTypeIsAssignable(GenTree* typeTo, GenTree* typeFrom);
51855186
GenTree* impGetGenericTypeDefinition(GenTree* type);
51865187

5187-
// Mirrors StringComparison.cs
5188-
enum StringComparison
5189-
{
5190-
Ordinal = 4,
5191-
OrdinalIgnoreCase = 5
5192-
};
5193-
enum class StringComparisonKind
5194-
{
5195-
Equals,
5196-
StartsWith,
5197-
EndsWith
5198-
};
5199-
GenTree* impUtf16StringComparison(StringComparisonKind kind, CORINFO_SIG_INFO* sig, unsigned methodFlags);
5200-
GenTree* impUtf16SpanComparison(StringComparisonKind kind, CORINFO_SIG_INFO* sig, unsigned methodFlags);
5201-
GenTree* impExpandHalfConstEquals(GenTreeLclVarCommon* data,
5202-
GenTree* lengthFld,
5203-
bool checkForNull,
5204-
StringComparisonKind kind,
5205-
WCHAR* cnsData,
5206-
int len,
5207-
int dataOffset,
5208-
StringComparison cmpMode);
5209-
GenTree* impExpandHalfConstEquals(
5210-
GenTreeLclVarCommon* data, WCHAR* cns, int len, int dataOffset, StringComparison cmpMode);
5211-
GenTreeStrCon* impGetStrConFromSpan(GenTree* span);
5212-
52135188
GenTree* impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
52145189
CORINFO_METHOD_HANDLE method,
52155190
CORINFO_SIG_INFO* sig,
@@ -9055,7 +9030,7 @@ class Compiler
90559030
GenTree* optVNConstantPropOnJTrue(BasicBlock* block, GenTree* test);
90569031
GenTree* optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, GenTree* tree);
90579032
GenTree* optVNBasedFoldExpr(BasicBlock* block, GenTree* parent, GenTree* tree);
9058-
GenTree* optVNBasedFoldExpr_Call(BasicBlock* block, GenTree* parent, GenTreeCall* call);
9033+
GenTree* optVNBasedFoldExpr_Call(GenTreeCall* call);
90599034
GenTree* optVNBasedFoldExpr_Call_Memmove(GenTreeCall* call);
90609035
GenTree* optVNBasedFoldExpr_Call_Memset(GenTreeCall* call);
90619036
GenTree* optVNBasedFoldExpr_Call_Memcmp(GenTreeCall* call);

src/coreclr/jit/fgprofile.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ PhaseStatus Compiler::fgPrepareToInstrumentMethod()
25452545
// These are marked as [Intrinsic] only to be handled (unrolled) for constant inputs.
25462546
// In other cases they have large managed implementations we want to profile.
25472547
case NI_System_String_Equals:
2548+
case NI_System_String_OrdinalEqualsIgnoreCase:
25482549
case NI_System_SpanHelpers_Memmove:
25492550
case NI_System_MemoryExtensions_Equals:
25502551
case NI_System_MemoryExtensions_SequenceEqual:

src/coreclr/jit/gentree.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14999,6 +14999,46 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree)
1499914999
}
1500015000
}
1500115001

15002+
//------------------------------------------------------------------------
15003+
// gtFoldExprConstChain: fold a tree into a constant when possible, recursing
15004+
// into operands first.
15005+
//
15006+
// Arguments:
15007+
// tree - the tree to fold (mutated in place)
15008+
// maxDepth - remaining recursion budget; folding stops (and the subtree is
15009+
// returned unfolded) once it is exhausted
15010+
//
15011+
// Returns:
15012+
// The folded tree; a constant node if the whole chain folded to a constant.
15013+
//
15014+
GenTree* Compiler::gtFoldExprConstChain(GenTree* tree, int maxDepth)
15015+
{
15016+
if (maxDepth <= 0)
15017+
{
15018+
return tree;
15019+
}
15020+
15021+
if (tree->OperIsUnary())
15022+
{
15023+
if (tree->AsOp()->gtOp1 != nullptr)
15024+
{
15025+
tree->AsOp()->gtOp1 = gtFoldExprConstChain(tree->AsOp()->gtOp1, maxDepth - 1);
15026+
}
15027+
}
15028+
else if (tree->OperIsBinary())
15029+
{
15030+
if (tree->AsOp()->gtOp1 != nullptr)
15031+
{
15032+
tree->AsOp()->gtOp1 = gtFoldExprConstChain(tree->AsOp()->gtOp1, maxDepth - 1);
15033+
}
15034+
if (tree->AsOp()->gtOp2 != nullptr)
15035+
{
15036+
tree->AsOp()->gtOp2 = gtFoldExprConstChain(tree->AsOp()->gtOp2, maxDepth - 1);
15037+
}
15038+
}
15039+
return gtFoldExpr(tree);
15040+
}
15041+
1500215042
//------------------------------------------------------------------------
1500315043
// gtFoldExprUnary: see if a unary operation is foldable
1500415044
//

src/coreclr/jit/importercalls.cpp

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,51 +3566,6 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
35663566
retNode = impArrayAccessIntrinsic(clsHnd, sig, memberRef, readonlyCall, ni);
35673567
break;
35683568

3569-
case NI_System_String_Equals:
3570-
{
3571-
retNode = impUtf16StringComparison(StringComparisonKind::Equals, sig, methodFlags);
3572-
break;
3573-
}
3574-
3575-
case NI_System_MemoryExtensions_Equals:
3576-
case NI_System_MemoryExtensions_SequenceEqual:
3577-
{
3578-
retNode = impUtf16SpanComparison(StringComparisonKind::Equals, sig, methodFlags);
3579-
break;
3580-
}
3581-
3582-
case NI_System_String_StartsWith:
3583-
{
3584-
retNode = impUtf16StringComparison(StringComparisonKind::StartsWith, sig, methodFlags);
3585-
break;
3586-
}
3587-
3588-
case NI_System_String_EndsWith:
3589-
{
3590-
retNode = impUtf16StringComparison(StringComparisonKind::EndsWith, sig, methodFlags);
3591-
break;
3592-
}
3593-
3594-
case NI_System_MemoryExtensions_StartsWith:
3595-
{
3596-
retNode = impUtf16SpanComparison(StringComparisonKind::StartsWith, sig, methodFlags);
3597-
break;
3598-
}
3599-
3600-
case NI_System_MemoryExtensions_EndsWith:
3601-
{
3602-
retNode = impUtf16SpanComparison(StringComparisonKind::EndsWith, sig, methodFlags);
3603-
break;
3604-
}
3605-
3606-
case NI_System_MemoryExtensions_AsSpan:
3607-
case NI_System_String_op_Implicit:
3608-
{
3609-
assert(sig->numArgs == 1);
3610-
isSpecial = impStackTop().val->OperIs(GT_CNS_STR);
3611-
break;
3612-
}
3613-
36143569
case NI_System_String_get_Chars:
36153570
{
36163571
GenTree* op2 = impPopStack().val;
@@ -4908,6 +4863,13 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
49084863
break;
49094864
}
49104865

4866+
case NI_System_String_OrdinalEqualsIgnoreCase:
4867+
{
4868+
// We'll try to fold/unroll this in VN for constant input.
4869+
isSpecial = true;
4870+
break;
4871+
}
4872+
49114873
case NI_System_SpanHelpers_Fill:
49124874
{
49134875
if (sig->sigInst.methInstCount == 1)
@@ -10937,6 +10899,16 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
1093710899
}
1093810900
}
1093910901
}
10902+
else if (strcmp(namespaceName, "Globalization") == 0)
10903+
{
10904+
if (strcmp(className, "Ordinal") == 0)
10905+
{
10906+
if (strcmp(methodName, "EqualsIgnoreCase") == 0)
10907+
{
10908+
result = NI_System_String_OrdinalEqualsIgnoreCase;
10909+
}
10910+
}
10911+
}
1094010912
else if (strcmp(namespaceName, "Numerics") == 0)
1094110913
{
1094210914
if (strcmp(className, "BitOperations") == 0)

0 commit comments

Comments
 (0)