Skip to content

Commit 0403fd9

Browse files
jgu222gfxbot
authored andcommitted
Given dessa CC = {a, b, c}, if "a = extElt V0, 0" and
"b = extElt V1, 0", where V0 != V1, only enable aliasing for one of two extElt instructions. To be able to alias both, it needs to coalesce V0 and V1. The current algo does not handle coalescing v0 and V1 as they are different values and no longer be treated as alias. A different algo is needed for handling this case Change-Id: I014ea28a06b9e2e1bf2efc51452d553cd70671c9
1 parent fc6a079 commit 0403fd9

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

IGC/Compiler/CISACodeGen/VariableReuseAnalysis.cpp

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,7 @@ void VariableReuseAnalysis::visitExtractElementInst(ExtractElementInst& I)
989989
// be merged into part of other value.)
990990
if (m_HasBecomeNoopInsts.count(EEI) ||
991991
m_DeSSA->isNoopAliaser(EEI) ||
992-
isOrCoalescedWithArg(EEI) ||
993-
isOrCoalescedWithArg(vecVal) ||
992+
!isSingleVecAliasee(vecVal) ||
994993
(m_WIA && m_WIA->whichDepend(EEI) != m_WIA->whichDepend(vecVal))) {
995994
return;
996995
}
@@ -1002,7 +1001,7 @@ void VariableReuseAnalysis::visitExtractElementInst(ExtractElementInst& I)
10021001
// skip it for now (implementation choice).
10031002
// Note that payload-coalescing does not use node value yet.
10041003
if (hasBeenPayloadCoalesced(EEI) ||
1005-
isVecAliaser(EEI_nv)) {
1004+
!isSingleVecAliaser(EEI_nv)) {
10061005
return;
10071006
}
10081007

@@ -1450,8 +1449,19 @@ void VariableReuseAnalysis::addVecAlias(
14501449
aliaserSV->Aliasers.clear();
14511450
}
14521451

1453-
// Finally, add aliaserSV into root's Aliaser vector
1452+
// Finally, add aliaserSV into root's Aliaser vector and
1453+
// update aliaser to its root map if aliaser's not isolated.
14541454
rootSV->Aliasers.push_back(aliaserSV);
1455+
// aliaser
1456+
Value* rv0 = m_DeSSA ? m_DeSSA->getRootValue(Aliaser) : nullptr;
1457+
if (rv0) {
1458+
m_root2AliasMap[rv0] = Aliaser;
1459+
}
1460+
// aliasee
1461+
Value* rv1 = m_DeSSA ? m_DeSSA->getRootValue(Aliasee) : nullptr;
1462+
if (rv1) {
1463+
m_root2AliasMap[rv1] = Aliasee;
1464+
}
14551465
}
14561466

14571467
SSubVecDesc* VariableReuseAnalysis::getOrCreateSubVecDesc(Value* V)
@@ -1463,15 +1473,43 @@ SSubVecDesc* VariableReuseAnalysis::getOrCreateSubVecDesc(Value* V)
14631473
return m_aliasMap[V];
14641474
}
14651475

1466-
bool VariableReuseAnalysis::isVecAliaser(llvm::Value* V) const
1476+
bool VariableReuseAnalysis::isVecAliased(Value* V) const
1477+
{
1478+
if (m_aliasMap.count(V) > 0) {
1479+
return true;
1480+
}
1481+
1482+
Value* rv = m_DeSSA ? m_DeSSA->getRootValue(V) : nullptr;
1483+
return (rv && m_root2AliasMap.count(rv) > 0);
1484+
}
1485+
1486+
bool VariableReuseAnalysis::isSingleVecAliaser(llvm::Value* V) const
14671487
{
14681488
auto II = m_aliasMap.find(V);
1469-
if (II == m_aliasMap.end())
1470-
return false;
1471-
SSubVecDesc* SV = II->second;
1472-
return SV->Aliaser != SV->BaseVector;
1489+
if (II != m_aliasMap.end()) {
1490+
SSubVecDesc* SV = II->second;
1491+
if (SV->Aliaser != SV->BaseVector)
1492+
return false;
1493+
}
1494+
1495+
return isSingleVecAliasee(V);
1496+
}
1497+
1498+
bool VariableReuseAnalysis::isSingleVecAliasee(llvm::Value* V) const
1499+
{
1500+
// Check if any value of its dessa CC has been aliased already.
1501+
Value* rv = m_DeSSA ? m_DeSSA->getRootValue(V) : nullptr;
1502+
if (rv) {
1503+
auto II = m_root2AliasMap.find(rv);
1504+
if (II != m_root2AliasMap.end()) {
1505+
Value* aV = II->second;
1506+
return V == aV;
1507+
}
1508+
}
1509+
return true;
14731510
}
14741511

1512+
14751513
// A chain of IEIs is used to define a vector. If all elements of this vector
14761514
// are inserted via this chain IEI that has a constant index, populate AllIEIs.
14771515
// input: FirstIEI (first IEI, usually with index = 0)

IGC/Compiler/CISACodeGen/VariableReuseAnalysis.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class VariableReuseAnalysis : public llvm::FunctionPass,
193193
typedef llvm::SmallVector<SVecInsEltInfo, 32> VecInsEltInfoTy;
194194
typedef llvm::DenseMap<llvm::Value*, SSubVecDesc*> AliasMapTy;
195195
typedef llvm::SmallVector<llvm::Value*, 32> ValueVectorTy;
196+
typedef llvm::DenseMap<llvm::Value*, llvm::Value*> Val2ValMapTy;
196197

197198
// following to be deleted
198199
typedef llvm::DenseMap<llvm::Value*, SSubVecDesc> ValueAliasMapTy;
@@ -283,8 +284,9 @@ class VariableReuseAnalysis : public llvm::FunctionPass,
283284
int getCongruentClassSize(llvm::Value* V);
284285
bool isSameSizeValue(llvm::Value* V0, llvm::Value* V1);
285286

286-
bool isVecAliased(llvm::Value* V) const { return m_aliasMap.count(V) > 0; }
287-
bool isVecAliaser(llvm::Value* V) const;
287+
bool isVecAliased(llvm::Value* V) const;
288+
bool isSingleVecAliaser(llvm::Value* V) const;
289+
bool isSingleVecAliasee(llvm::Value* V) const;
288290

289291
// getRootValue():
290292
// return dessa root value; if dessa root value
@@ -400,6 +402,7 @@ class VariableReuseAnalysis : public llvm::FunctionPass,
400402
m_ValueAliasMap.clear();
401403
m_AliasRootMap.clear();
402404
m_aliasMap.clear();
405+
m_root2AliasMap.clear();
403406
m_HasBecomeNoopInsts.clear();
404407
}
405408

@@ -533,6 +536,13 @@ class VariableReuseAnalysis : public llvm::FunctionPass,
533536
//SmallPtrSet<llvm::Instruction*, 16> m_Visited;
534537
ValueAliasMapTy m_ExtractFrom;
535538
ValueAliasMapTy m_insertTo;
539+
540+
// Temporaries under VATemp
541+
// if a value V is in a dessa CC and V is aliased,
542+
// add <V's root, V> into the map. This is a quick
543+
// way to check if any of values in a dessa CC has
544+
// been aliased (either aliaser or aliasee)
545+
Val2ValMapTy m_root2AliasMap;
536546
};
537547

538548
llvm::FunctionPass *createVariableReuseAnalysisPass();

0 commit comments

Comments
 (0)