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: Change VN's representation for phi definitions #105198

Merged
merged 2 commits into from
Jul 23, 2024
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
31 changes: 15 additions & 16 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5162,24 +5162,13 @@ bool Compiler::optVNIsLoopInvariant(ValueNum vn, FlowGraphNaturalLoop* loop, VNS
return previousRes;
}

bool res = true;
VNFuncApp funcApp;
bool res = true;
VNFuncApp funcApp;
VNPhiDef phiDef;
VNMemoryPhiDef memoryPhiDef;
if (vnStore->GetVNFunc(vn, &funcApp))
{
if (funcApp.m_func == VNF_PhiDef)
{
// Is the definition within the loop? If so, is not loop-invariant.
unsigned lclNum = funcApp.m_args[0];
unsigned ssaNum = funcApp.m_args[1];
LclSsaVarDsc* ssaDef = lvaTable[lclNum].GetPerSsaData(ssaNum);
res = !loop->ContainsBlock(ssaDef->GetBlock());
}
else if (funcApp.m_func == VNF_PhiMemoryDef)
{
BasicBlock* defnBlk = reinterpret_cast<BasicBlock*>(vnStore->ConstantValue<ssize_t>(funcApp.m_args[0]));
res = !loop->ContainsBlock(defnBlk);
}
else if (funcApp.m_func == VNF_MemOpaque)
if (funcApp.m_func == VNF_MemOpaque)
{
const unsigned loopIndex = funcApp.m_args[0];

Expand Down Expand Up @@ -5239,6 +5228,16 @@ bool Compiler::optVNIsLoopInvariant(ValueNum vn, FlowGraphNaturalLoop* loop, VNS
}
}
}
else if (vnStore->GetPhiDef(vn, &phiDef))
{
// Is the definition within the loop? If so, is not loop-invariant.
LclSsaVarDsc* ssaDef = lvaTable[phiDef.LclNum].GetPerSsaData(phiDef.SsaDef);
res = !loop->ContainsBlock(ssaDef->GetBlock());
}
else if (vnStore->GetMemoryPhiDef(vn, &memoryPhiDef))
{
res = !loop->ContainsBlock(memoryPhiDef.Block);
}

loopVnInvariantCache->Set(vn, res);
return res;
Expand Down
14 changes: 6 additions & 8 deletions src/coreclr/jit/redundantbranchopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1398,8 +1398,8 @@ bool Compiler::optJumpThreadPhi(BasicBlock* block, GenTree* tree, ValueNum treeN
for (int i = 0; i < 2; i++)
{
const ValueNum phiDefVN = treeNormVNFuncApp.m_args[i];
VNFuncApp phiDefFuncApp;
if (!vnStore->GetVNFunc(phiDefVN, &phiDefFuncApp) || (phiDefFuncApp.m_func != VNF_PhiDef))
VNPhiDef phiDef;
if (!vnStore->GetPhiDef(phiDefVN, &phiDef))
{
// This input is not a phi def. If it's a func app it might depend on
// transitively on a phi def; consider a general search utility.
Expand All @@ -1409,12 +1409,10 @@ bool Compiler::optJumpThreadPhi(BasicBlock* block, GenTree* tree, ValueNum treeN

// The PhiDef args tell us which local and which SSA def of that local.
//
assert(phiDefFuncApp.m_arity == 3);
const unsigned lclNum = unsigned(phiDefFuncApp.m_args[0]);
const unsigned ssaDefNum = unsigned(phiDefFuncApp.m_args[1]);
const ValueNum phiVN = ValueNum(phiDefFuncApp.m_args[2]);
JITDUMP("... JT-PHI [interestingVN] in " FMT_BB " relop %s operand VN is PhiDef for V%02u:%u " FMT_VN "\n",
block->bbNum, i == 0 ? "first" : "second", lclNum, ssaDefNum, phiVN);
const unsigned lclNum = phiDef.LclNum;
const unsigned ssaDefNum = phiDef.SsaDef;
JITDUMP("... JT-PHI [interestingVN] in " FMT_BB " relop %s operand VN is PhiDef for V%02u\n", block->bbNum,
i == 0 ? "first" : "second", lclNum, ssaDefNum);
if (!foundPhiDef)
{
DISPTREE(tree);
Expand Down
Loading
Loading