Skip to content

Commit 33e6a9a

Browse files
authored
[IR2Vec] Added fixme for cyclic dependency in Flow-Aware embedding computation (#162522)
1 parent 4f6cb06 commit 33e6a9a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

llvm/lib/Analysis/IR2Vec.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,21 @@ void FlowAwareEmbedder::computeEmbeddings(const BasicBlock &BB) const {
239239
// If the operand is defined elsewhere, we use its embedding
240240
if (const auto *DefInst = dyn_cast<Instruction>(Op)) {
241241
auto DefIt = InstVecMap.find(DefInst);
242-
assert(DefIt != InstVecMap.end() &&
243-
"Instruction should have been processed before its operands");
244-
ArgEmb += DefIt->second;
245-
continue;
242+
// Fixme (#159171): Ideally we should never miss an instruction
243+
// embedding here.
244+
// But when we have cyclic dependencies (e.g., phi
245+
// nodes), we might miss the embedding. In such cases, we fall back to
246+
// using the vocabulary embedding. This can be fixed by iterating to a
247+
// fixed-point, or by using a simple solver for the set of simultaneous
248+
// equations.
249+
// Another case when we might miss an instruction embedding is when
250+
// the operand instruction is in a different basic block that has not
251+
// been processed yet. This can be fixed by processing the basic blocks
252+
// in a topological order.
253+
if (DefIt != InstVecMap.end())
254+
ArgEmb += DefIt->second;
255+
else
256+
ArgEmb += Vocab[*Op];
246257
}
247258
// If the operand is not defined by an instruction, we use the vocabulary
248259
else {

0 commit comments

Comments
 (0)