Skip to content

Conversation

svkeerthy
Copy link
Contributor

@svkeerthy svkeerthy commented Oct 7, 2025

Tests for #162165. Missed it earlier.

@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Oct 7, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2025

@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-analysis

Author: S. VenkataKeerthy (svkeerthy)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Analysis/IR2Vec.cpp (+2)
  • (modified) llvm/unittests/Analysis/IR2VecTest.cpp (+54)
diff --git a/llvm/lib/Analysis/IR2Vec.cpp b/llvm/lib/Analysis/IR2Vec.cpp
index 295b6d33525d9..688535161d4b9 100644
--- a/llvm/lib/Analysis/IR2Vec.cpp
+++ b/llvm/lib/Analysis/IR2Vec.cpp
@@ -200,6 +200,8 @@ void Embedder::computeEmbeddings() const {
   if (F.isDeclaration())
     return;
 
+  FuncVector = Embedding(Dimension, 0.0);
+
   // Consider only the basic blocks that are reachable from entry
   for (const BasicBlock *BB : depth_first(&F)) {
     computeEmbeddings(*BB);
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index d136cb6a316b1..ee14596bcb8ca 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -430,6 +430,60 @@ TEST_F(IR2VecTestFixture, GetFunctionVector_FlowAware) {
   EXPECT_TRUE(FuncVec.approximatelyEquals(Embedding(2, 58.1)));
 }
 
+TEST_F(IR2VecTestFixture, MultipleComputeEmbeddingsConsistency_Symbolic) {
+  auto Emb = Embedder::create(IR2VecKind::Symbolic, *F, *V);
+  ASSERT_TRUE(static_cast<bool>(Emb));
+
+  // Get initial function vector
+  const auto &FuncVec1 = Emb->getFunctionVector();
+  
+  // Compute embeddings again by calling getFunctionVector multiple times
+  const auto &FuncVec2 = Emb->getFunctionVector();
+  const auto &FuncVec3 = Emb->getFunctionVector();
+
+  // All function vectors should be identical
+  EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec2));
+  EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec3));
+  EXPECT_TRUE(FuncVec2.approximatelyEquals(FuncVec3));
+
+  // Also check that instruction vectors remain consistent
+  const auto &InstMap1 = Emb->getInstVecMap();
+  const auto &InstMap2 = Emb->getInstVecMap();
+  
+  EXPECT_EQ(InstMap1.size(), InstMap2.size());
+  for (const auto &[Inst, Vec1] : InstMap1) {
+    ASSERT_TRUE(InstMap2.count(Inst));
+    EXPECT_TRUE(Vec1.approximatelyEquals(InstMap2.at(Inst)));
+  }
+}
+
+TEST_F(IR2VecTestFixture, MultipleComputeEmbeddingsConsistency_FlowAware) {
+  auto Emb = Embedder::create(IR2VecKind::FlowAware, *F, *V);
+  ASSERT_TRUE(static_cast<bool>(Emb));
+
+  // Get initial function vector
+  const auto &FuncVec1 = Emb->getFunctionVector();
+  
+  // Compute embeddings again by calling getFunctionVector multiple times
+  const auto &FuncVec2 = Emb->getFunctionVector();
+  const auto &FuncVec3 = Emb->getFunctionVector();
+
+  // All function vectors should be identical
+  EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec2));
+  EXPECT_TRUE(FuncVec1.approximatelyEquals(FuncVec3));
+  EXPECT_TRUE(FuncVec2.approximatelyEquals(FuncVec3));
+
+  // Also check that instruction vectors remain consistent
+  const auto &InstMap1 = Emb->getInstVecMap();
+  const auto &InstMap2 = Emb->getInstVecMap();
+  
+  EXPECT_EQ(InstMap1.size(), InstMap2.size());
+  for (const auto &[Inst, Vec1] : InstMap1) {
+    ASSERT_TRUE(InstMap2.count(Inst));
+    EXPECT_TRUE(Vec1.approximatelyEquals(InstMap2.at(Inst)));
+  }
+}
+
 static constexpr unsigned MaxOpcodes = Vocabulary::MaxOpcodes;
 [[maybe_unused]]
 static constexpr unsigned MaxTypeIDs = Vocabulary::MaxTypeIDs;

@svkeerthy svkeerthy requested a review from mtrofin October 7, 2025 20:21
Copy link

github-actions bot commented Oct 7, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the tests only differ by a single enum value, this seems like a good case for use of a value-parameterized test. https://google.github.io/googletest/advanced.html#value-parameterized-tests

@svkeerthy
Copy link
Contributor Author

Given the tests only differ by a single enum value, this seems like a good case for use of a value-parameterized test. https://google.github.io/googletest/advanced.html#value-parameterized-tests

Thanks. Will do it for all the applicable tests together in a separate patch. There are many such instances in IR2VecTest.

@svkeerthy svkeerthy merged commit 2353088 into main Oct 7, 2025
9 checks passed
@svkeerthy svkeerthy deleted the users/svkeerthy/10-06-ir2vec-initialization branch October 7, 2025 23:05
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 7, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building llvm at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/16890

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp   -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


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.

5 participants