Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Intrinsify UTF16->UTF8 conversion for string literals (Encoding.UTF8.TryGetBytes) #85328

Merged
merged 15 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4874,6 +4874,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
bool doBranchOpt = true;
bool doCse = true;
bool doAssertionProp = true;
bool doVNBasedIntrinExpansion = true;
bool doRangeAnalysis = true;
bool doVNBasedDeadStoreRemoval = true;
int iterations = 1;
Expand All @@ -4887,6 +4888,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
doBranchOpt = doValueNum && (JitConfig.JitDoRedundantBranchOpts() != 0);
doCse = doValueNum;
doAssertionProp = doValueNum && (JitConfig.JitDoAssertionProp() != 0);
doVNBasedIntrinExpansion = doValueNum;
doRangeAnalysis = doAssertionProp && (JitConfig.JitDoRangeAnalysis() != 0);
doVNBasedDeadStoreRemoval = doValueNum && (JitConfig.JitDoVNBasedDeadStoreRemoval() != 0);

Expand Down Expand Up @@ -4970,6 +4972,13 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
DoPhase(this, PHASE_ASSERTION_PROP_MAIN, &Compiler::optAssertionPropMain);
}

if (doVNBasedIntrinExpansion)
{
// Expand some intrinsics based on VN data
//
DoPhase(this, PHASE_VN_BASED_INTRINSIC_EXPAND, &Compiler::fgVNBasedIntrinsicExpansion);
}

if (doRangeAnalysis)
{
// Bounds check elimination via range analysis
Expand Down
46 changes: 45 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5203,6 +5203,8 @@ class Compiler
}
}

bool GetObjectHandleAndOffset(GenTree* tree, ssize_t* byteOffset, CORINFO_OBJECT_HANDLE* pObj);

// Convert a BYTE which represents the VM's CorInfoGCtype to the JIT's var_types
var_types getJitGCType(BYTE gcType);

Expand Down Expand Up @@ -5346,6 +5348,10 @@ class Compiler
PhaseStatus fgExpandStaticInit();
bool fgExpandStaticInitForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);

PhaseStatus fgVNBasedIntrinsicExpansion();
bool fgVNBasedIntrinsicExpansionForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);
bool fgVNBasedIntrinsicExpansionForCall_ReadUtf8(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);

PhaseStatus fgInsertGCPolls();
BasicBlock* fgCreateGCPoll(GCPollType pollType, BasicBlock* block);

Expand Down Expand Up @@ -7074,6 +7080,7 @@ class Compiler
#define OMF_HAS_MDARRAYREF 0x00004000 // Method contains multi-dimensional intrinsic array element loads or stores.
#define OMF_HAS_STATIC_INIT 0x00008000 // Method has static initializations we might want to partially inline
#define OMF_HAS_TLS_FIELD 0x00010000 // Method contains TLS field access
#define OMF_HAS_SPECIAL_INTRINSICS 0x00020000 // Method contains special intrinsics expanded in late phases

// clang-format on

Expand Down Expand Up @@ -7134,6 +7141,16 @@ class Compiler
optMethodFlags |= OMF_HAS_TLS_FIELD;
}

bool doesMethodHaveSpecialIntrinsics()
{
return (optMethodFlags & OMF_HAS_SPECIAL_INTRINSICS) != 0;
}

void setMethodHasSpecialIntrinsics()
{
optMethodFlags |= OMF_HAS_SPECIAL_INTRINSICS;
}

void pickGDV(GenTreeCall* call,
IL_OFFSET ilOffset,
bool isInterface,
Expand Down Expand Up @@ -8934,7 +8951,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

public:
// Similar to roundUpSIMDSize, but for General Purpose Registers (GPR)
unsigned int roundUpGPRSize(unsigned size)
unsigned roundUpGPRSize(unsigned size)
{
if (size > 4 && (REGSIZE_BYTES == 8))
{
Expand All @@ -8947,6 +8964,33 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return size; // 2, 1, 0
}

var_types roundDownMaxType(unsigned size)
{
assert(size > 0);
var_types result = TYP_UNDEF;
#ifdef FEATURE_SIMD
if (IsBaselineSimdIsaSupported() && (roundDownSIMDSize(size) > 0))
{
return getSIMDTypeForSize(roundDownSIMDSize(size));
}
#endif
int nearestPow2 = 1 << BitOperations::Log2((unsigned)size);
switch (min(nearestPow2, REGSIZE_BYTES))
{
case 1:
return TYP_UBYTE;
case 2:
return TYP_USHORT;
case 4:
return TYP_INT;
case 8:
assert(REGSIZE_BYTES == 8);
return TYP_LONG;
default:
unreached();
}
}

enum UnrollKind
{
Memset,
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ CompPhaseNameMacro(PHASE_VALUE_NUMBER, "Do value numbering",
CompPhaseNameMacro(PHASE_OPTIMIZE_INDEX_CHECKS, "Optimize index checks", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_VALNUM_CSES, "Optimize Valnum CSEs", false, -1, false)
CompPhaseNameMacro(PHASE_VN_COPY_PROP, "VN based copy prop", false, -1, false)
CompPhaseNameMacro(PHASE_VN_BASED_INTRINSIC_EXPAND, "VN based intrinsic expansion", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_BRANCHES, "Redundant branch opts", false, -1, false)
CompPhaseNameMacro(PHASE_ASSERTION_PROP_MAIN, "Assertion prop", false, -1, false)
CompPhaseNameMacro(PHASE_IF_CONVERSION, "If conversion", false, -1, false)
Expand Down
Loading
Loading