Skip to content

Conversation

svkeerthy
Copy link
Contributor

No description provided.

@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Oct 8, 2025
@svkeerthy svkeerthy requested a review from mtrofin October 8, 2025 18:24
@llvmbot
Copy link
Member

llvmbot commented Oct 8, 2025

@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-analysis

Author: S. VenkataKeerthy (svkeerthy)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/162522.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/IR2Vec.cpp (+15-4)
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 688535161d4b9..1794a604b991d 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -239,10 +239,21 @@ void FlowAwareEmbedder::computeEmbeddings(const BasicBlock &BB) const {
       // If the operand is defined elsewhere, we use its embedding
       if (const auto *DefInst = dyn_cast<Instruction>(Op)) {
         auto DefIt = InstVecMap.find(DefInst);
-        assert(DefIt != InstVecMap.end() &&
-               "Instruction should have been processed before its operands");
-        ArgEmb += DefIt->second;
-        continue;
+        // Fixme (#159171): Ideally we should never miss an instruction
+        // embedding here.
+        // But when we have cyclic dependencies (e.g., phi
+        // nodes), we might miss the embedding. In such cases, we fall back to
+        // using the vocabulary embedding. This can be fixed by iterating to a
+        // fixed-point, or by using a simple solver for the set of simultaneous
+        // equations.
+        // Another case when we might miss an instruction embedding is when
+        // the operand instruction is in a different basic block that has not
+        // been processed yet. This can be fixed by processing the basic blocks
+        // in a topological order.
+        if (DefIt != InstVecMap.end())
+          ArgEmb += DefIt->second;
+        else
+          ArgEmb += Vocab[*Op];
       }
       // If the operand is not defined by an instruction, we use the vocabulary
       else {

@svkeerthy svkeerthy merged commit 33e6a9a into main Oct 8, 2025
10 of 11 checks passed
@svkeerthy svkeerthy deleted the users/svkeerthy/10-08-ir2vec-fa-fix branch October 8, 2025 19:13
clingfei pushed a commit to clingfei/llvm-project that referenced this pull request Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding mlgo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants