Skip to content

Commit 7d86f88

Browse files
authored
JIT: Change VN's representation for phi definitions (#105198)
Replace `VNF_PhiDef` and `VNF_MemoryPhiDef` by new explicit representations that represent all phi args directly.
1 parent 98b165d commit 7d86f88

File tree

5 files changed

+383
-253
lines changed

5 files changed

+383
-253
lines changed

src/coreclr/jit/optimizer.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5162,24 +5162,13 @@ bool Compiler::optVNIsLoopInvariant(ValueNum vn, FlowGraphNaturalLoop* loop, VNS
51625162
return previousRes;
51635163
}
51645164

5165-
bool res = true;
5166-
VNFuncApp funcApp;
5165+
bool res = true;
5166+
VNFuncApp funcApp;
5167+
VNPhiDef phiDef;
5168+
VNMemoryPhiDef memoryPhiDef;
51675169
if (vnStore->GetVNFunc(vn, &funcApp))
51685170
{
5169-
if (funcApp.m_func == VNF_PhiDef)
5170-
{
5171-
// Is the definition within the loop? If so, is not loop-invariant.
5172-
unsigned lclNum = funcApp.m_args[0];
5173-
unsigned ssaNum = funcApp.m_args[1];
5174-
LclSsaVarDsc* ssaDef = lvaTable[lclNum].GetPerSsaData(ssaNum);
5175-
res = !loop->ContainsBlock(ssaDef->GetBlock());
5176-
}
5177-
else if (funcApp.m_func == VNF_PhiMemoryDef)
5178-
{
5179-
BasicBlock* defnBlk = reinterpret_cast<BasicBlock*>(vnStore->ConstantValue<ssize_t>(funcApp.m_args[0]));
5180-
res = !loop->ContainsBlock(defnBlk);
5181-
}
5182-
else if (funcApp.m_func == VNF_MemOpaque)
5171+
if (funcApp.m_func == VNF_MemOpaque)
51835172
{
51845173
const unsigned loopIndex = funcApp.m_args[0];
51855174

@@ -5239,6 +5228,16 @@ bool Compiler::optVNIsLoopInvariant(ValueNum vn, FlowGraphNaturalLoop* loop, VNS
52395228
}
52405229
}
52415230
}
5231+
else if (vnStore->GetPhiDef(vn, &phiDef))
5232+
{
5233+
// Is the definition within the loop? If so, is not loop-invariant.
5234+
LclSsaVarDsc* ssaDef = lvaTable[phiDef.LclNum].GetPerSsaData(phiDef.SsaDef);
5235+
res = !loop->ContainsBlock(ssaDef->GetBlock());
5236+
}
5237+
else if (vnStore->GetMemoryPhiDef(vn, &memoryPhiDef))
5238+
{
5239+
res = !loop->ContainsBlock(memoryPhiDef.Block);
5240+
}
52425241

52435242
loopVnInvariantCache->Set(vn, res);
52445243
return res;

src/coreclr/jit/redundantbranchopts.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,8 @@ bool Compiler::optJumpThreadPhi(BasicBlock* block, GenTree* tree, ValueNum treeN
13981398
for (int i = 0; i < 2; i++)
13991399
{
14001400
const ValueNum phiDefVN = treeNormVNFuncApp.m_args[i];
1401-
VNFuncApp phiDefFuncApp;
1402-
if (!vnStore->GetVNFunc(phiDefVN, &phiDefFuncApp) || (phiDefFuncApp.m_func != VNF_PhiDef))
1401+
VNPhiDef phiDef;
1402+
if (!vnStore->GetPhiDef(phiDefVN, &phiDef))
14031403
{
14041404
// This input is not a phi def. If it's a func app it might depend on
14051405
// transitively on a phi def; consider a general search utility.
@@ -1409,12 +1409,10 @@ bool Compiler::optJumpThreadPhi(BasicBlock* block, GenTree* tree, ValueNum treeN
14091409

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

0 commit comments

Comments
 (0)