-
Notifications
You must be signed in to change notification settings - Fork 5.2k
JIT: Do not propagate some constants #70378
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
Changes from 5 commits
593a3ec
72ab579
83fc086
d81b195
1d076dd
0274989
69e4d1d
3920a54
7873570
bc40d08
eaede4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3177,6 +3177,67 @@ GenTree* Compiler::optVNConstantPropOnTree(BasicBlock* block, GenTree* tree) | |
|
|
||
| if (conValTree != nullptr) | ||
| { | ||
| if (tree->OperIs(GT_LCL_VAR) && conValTree->OperIs(GT_CNS_VEC, GT_CNS_DBL)) | ||
| { | ||
| // A simple heuristic: If the constant is defined outside of a loop (not far from its head) | ||
| // and is used inside it - don't propagate. | ||
|
|
||
| bool keepPropagating = false; | ||
|
|
||
| if (conValTree->OperIs(GT_CNS_VEC)) | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (conValTree->IsVectorZero() || conValTree->IsVectorAllBitsSet()) | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // These are cheap to materialize | ||
| keepPropagating = true; | ||
| } | ||
| } | ||
| else if (conValTree->OperIs(GT_CNS_DBL)) | ||
| { | ||
| if (conValTree->IsFloatPositiveZero()) | ||
| { | ||
| // This is cheap to materialize | ||
| keepPropagating = true; | ||
| } | ||
| #if defined(TARGET_ARM64) | ||
| if (emitter::canEncodeFloatImm8(conValTree->AsDblCon()->gtDconVal)) | ||
| { | ||
| // Such floats are likely immable on arm64 | ||
| keepPropagating = true; | ||
| } | ||
| #endif | ||
| } | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!keepPropagating) | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // Try to find the block this constant was originally defined in | ||
| const unsigned lclNum = tree->AsLclVarCommon()->GetLclNum(); | ||
| const unsigned ssaNum = GetSsaNumForLocalVarDef(tree); | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (ssaNum != SsaConfig::RESERVED_SSA_NUM) | ||
| { | ||
| BasicBlock* defBlock = lvaTable[lclNum].GetPerSsaData(ssaNum)->GetBlock(); | ||
|
||
| if (defBlock != nullptr) | ||
| { | ||
| // TODO: if it lives across calls in that loops we should propagate it only after those | ||
| // calls on ABIs without callee-saved registers to avoid spills | ||
| if (!defBlock->IsInLoop() && block->IsInLoop()) | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // Last, let's limit it to cases where block is not some not-always-taken | ||
| // block inside that loop | ||
EgorBo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const weight_t defBlockWeight = defBlock->getBBWeight(this); | ||
| const weight_t blockWeight = block->getBBWeight(this); | ||
|
|
||
| if ((defBlockWeight > 0) && ((blockWeight / defBlockWeight) >= BB_LOOP_WEIGHT_SCALE)) | ||
| { | ||
| JITDUMP("Skip constant propagation inside loop " FMT_BB "\n", block->bbNum); | ||
| return nullptr; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Were able to optimize. | ||
| conValTree->gtVNPair = vnPair; | ||
| GenTree* sideEffList = optExtractSideEffListFromConst(tree); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.