Skip to content

[ctx_prof] Fix ProfileAnnotator::allTakenPathsExit #109183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mtrofin
Copy link
Member

@mtrofin mtrofin commented Sep 18, 2024

Added tests to the validator and fixed issues stemming from the previous skipping over BBs with single successors - which is incorrect. That would be now picked by added tests where the assertions are expected to be triggered.

Copy link
Member Author

mtrofin commented Sep 18, 2024

2 similar comments
Copy link
Member Author

mtrofin commented Sep 18, 2024

Copy link
Member Author

mtrofin commented Sep 18, 2024

@mtrofin mtrofin marked this pull request as ready for review September 18, 2024 19:58
@llvmbot llvmbot added PGO Profile Guided Optimizations llvm:analysis llvm:transforms labels Sep 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-analysis

Author: Mircea Trofin (mtrofin)

Changes

Added tests to the validator and fixed issues stemming from the previous skipping over BBs with single successors - which is incorrect. That would be now picked by added tests where the assertions are expected to be triggered.


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp (+19-10)
  • (added) llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll (+85)
diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
index e76689e2f5f0a5..91f950e2ba4c3e 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
@@ -233,28 +233,37 @@ class ProfileAnnotator final {
     std::deque<const BasicBlock *> Worklist;
     DenseSet<const BasicBlock *> Visited;
     Worklist.push_back(&F.getEntryBlock());
-    Visited.insert(&F.getEntryBlock());
+    bool HitExit = false;
     while (!Worklist.empty()) {
       const auto *BB = Worklist.front();
       Worklist.pop_front();
-      if (succ_size(BB) <= 1)
+      if (!Visited.insert(BB).second)
         continue;
+      if (succ_size(BB) == 0) {
+        if (isa<UnreachableInst>(BB->getTerminator()))
+          return false;
+        HitExit = true;
+        continue;
+      }
+      if (succ_size(BB) == 1) {
+        llvm::append_range(Worklist, successors(BB));
+        continue;
+      }
       const auto &BBInfo = getBBInfo(*BB);
-      bool Inserted = false;
+      bool HasAWayOut = false;
       for (auto I = 0U; I < BB->getTerminator()->getNumSuccessors(); ++I) {
         const auto *Succ = BB->getTerminator()->getSuccessor(I);
         if (!shouldExcludeEdge(*BB, *Succ)) {
-          if (BBInfo.getEdgeCount(I) > 0)
-            if (Visited.insert(Succ).second) {
-              Worklist.push_back(Succ);
-              Inserted = true;
-            }
+          if (BBInfo.getEdgeCount(I) > 0) {
+            HasAWayOut = true;
+            Worklist.push_back(Succ);
+          }
         }
       }
-      if (!Inserted)
+      if (!HasAWayOut)
         return false;
     }
-    return true;
+    return HitExit;
   }
 
 public:
diff --git a/llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll b/llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll
new file mode 100644
index 00000000000000..dbe14c3522a8a9
--- /dev/null
+++ b/llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll
@@ -0,0 +1,85 @@
+; REQUIRES: asserts
+; Check that the profile annotator works: we hit an exit and non-zero paths to
+; already visited blocks are not disconsidered.
+;
+; RUN: split-file %s %t
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_ok.json --output=%t/profile_ok.ctxprofdata
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_pump.json --output=%t/profile_pump.ctxprofdata
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_unreachable.json --output=%t/profile_unreachable.ctxprofdata
+;
+; RUN: opt -passes=ctx-prof-flatten %t/example_ok.ll -use-ctx-profile=%t/profile_ok.ctxprofdata -S -o - | FileCheck %s
+; RUN: not --crash opt -passes=ctx-prof-flatten %t/message_pump.ll -use-ctx-profile=%t/profile_pump.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION
+; RUN: not --crash opt -passes=ctx-prof-flatten %t/unreachable.ll -use-ctx-profile=%t/profile_unreachable.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION
+
+; CHECK: br i1 %x, label %b1, label %exit, !prof ![[PROF1:[0-9]+]]
+; CHECK: br i1 %y, label %blk, label %exit, !prof ![[PROF2:[0-9]+]]
+; CHECK: ![[PROF1]] = !{!"branch_weights", i32 1, i32 1}
+; CHECK: ![[PROF2]] = !{!"branch_weights", i32 0, i32 1}
+; ASSERTION: Assertion `allTakenPathsExit()
+
+; b1->exit is the only way out from b1, but the exit block would have been
+; already visited from blk. That should not result in an assertion, though.
+;--- example_ok.ll
+define void @foo(i32 %t) !guid !0 {
+entry:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
+  br label %blk
+blk:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
+  %x = icmp eq i32 %t, 0
+  br i1 %x, label %b1, label %exit
+b1:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
+  %y = icmp eq i32 %t, 0
+  br i1 %y, label %blk, label %exit
+exit:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3)
+  ret void
+}
+!0 = !{i64 1234}
+
+;--- profile_ok.json
+[{"Guid":1234, "Counters":[2, 2, 1, 2]}]
+
+;--- message_pump.ll
+; This is a message pump: the loop never exits. This should result in an
+; assertion because we can't reach an exit BB
+
+define void @foo(i32 %t) !guid !0 {
+entry:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)  
+  br label %blk
+blk:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
+  %x = icmp eq i32 %t, 0
+  br i1 %x, label %blk, label %exit
+exit:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
+  ret void
+}
+!0 = !{i64 1234}
+
+;--- profile_pump.json
+[{"Guid":1234, "Counters":[2, 10, 0]}]
+
+;--- unreachable.ll
+; An unreachable block is reached, that's an error
+define void @foo(i32 %t) !guid !0 {
+entry:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
+  br label %blk
+blk:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
+  %x = icmp eq i32 %t, 0
+  br i1 %x, label %b1, label %exit
+b1:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
+  unreachable
+exit:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3)
+  ret void
+}
+!0 = !{i64 1234}
+
+;--- profile_unreachable.json
+[{"Guid":1234, "Counters":[2, 1, 1, 2]}]
\ No newline at end of file

@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2024

@llvm/pr-subscribers-pgo

Author: Mircea Trofin (mtrofin)

Changes

Added tests to the validator and fixed issues stemming from the previous skipping over BBs with single successors - which is incorrect. That would be now picked by added tests where the assertions are expected to be triggered.


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp (+19-10)
  • (added) llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll (+85)
diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
index e76689e2f5f0a5..91f950e2ba4c3e 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
@@ -233,28 +233,37 @@ class ProfileAnnotator final {
     std::deque<const BasicBlock *> Worklist;
     DenseSet<const BasicBlock *> Visited;
     Worklist.push_back(&F.getEntryBlock());
-    Visited.insert(&F.getEntryBlock());
+    bool HitExit = false;
     while (!Worklist.empty()) {
       const auto *BB = Worklist.front();
       Worklist.pop_front();
-      if (succ_size(BB) <= 1)
+      if (!Visited.insert(BB).second)
         continue;
+      if (succ_size(BB) == 0) {
+        if (isa<UnreachableInst>(BB->getTerminator()))
+          return false;
+        HitExit = true;
+        continue;
+      }
+      if (succ_size(BB) == 1) {
+        llvm::append_range(Worklist, successors(BB));
+        continue;
+      }
       const auto &BBInfo = getBBInfo(*BB);
-      bool Inserted = false;
+      bool HasAWayOut = false;
       for (auto I = 0U; I < BB->getTerminator()->getNumSuccessors(); ++I) {
         const auto *Succ = BB->getTerminator()->getSuccessor(I);
         if (!shouldExcludeEdge(*BB, *Succ)) {
-          if (BBInfo.getEdgeCount(I) > 0)
-            if (Visited.insert(Succ).second) {
-              Worklist.push_back(Succ);
-              Inserted = true;
-            }
+          if (BBInfo.getEdgeCount(I) > 0) {
+            HasAWayOut = true;
+            Worklist.push_back(Succ);
+          }
         }
       }
-      if (!Inserted)
+      if (!HasAWayOut)
         return false;
     }
-    return true;
+    return HitExit;
   }
 
 public:
diff --git a/llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll b/llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll
new file mode 100644
index 00000000000000..dbe14c3522a8a9
--- /dev/null
+++ b/llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll
@@ -0,0 +1,85 @@
+; REQUIRES: asserts
+; Check that the profile annotator works: we hit an exit and non-zero paths to
+; already visited blocks are not disconsidered.
+;
+; RUN: split-file %s %t
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_ok.json --output=%t/profile_ok.ctxprofdata
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_pump.json --output=%t/profile_pump.ctxprofdata
+; RUN: llvm-ctxprof-util fromJSON --input=%t/profile_unreachable.json --output=%t/profile_unreachable.ctxprofdata
+;
+; RUN: opt -passes=ctx-prof-flatten %t/example_ok.ll -use-ctx-profile=%t/profile_ok.ctxprofdata -S -o - | FileCheck %s
+; RUN: not --crash opt -passes=ctx-prof-flatten %t/message_pump.ll -use-ctx-profile=%t/profile_pump.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION
+; RUN: not --crash opt -passes=ctx-prof-flatten %t/unreachable.ll -use-ctx-profile=%t/profile_unreachable.ctxprofdata -S 2>&1 | FileCheck %s --check-prefix=ASSERTION
+
+; CHECK: br i1 %x, label %b1, label %exit, !prof ![[PROF1:[0-9]+]]
+; CHECK: br i1 %y, label %blk, label %exit, !prof ![[PROF2:[0-9]+]]
+; CHECK: ![[PROF1]] = !{!"branch_weights", i32 1, i32 1}
+; CHECK: ![[PROF2]] = !{!"branch_weights", i32 0, i32 1}
+; ASSERTION: Assertion `allTakenPathsExit()
+
+; b1->exit is the only way out from b1, but the exit block would have been
+; already visited from blk. That should not result in an assertion, though.
+;--- example_ok.ll
+define void @foo(i32 %t) !guid !0 {
+entry:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
+  br label %blk
+blk:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
+  %x = icmp eq i32 %t, 0
+  br i1 %x, label %b1, label %exit
+b1:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
+  %y = icmp eq i32 %t, 0
+  br i1 %y, label %blk, label %exit
+exit:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3)
+  ret void
+}
+!0 = !{i64 1234}
+
+;--- profile_ok.json
+[{"Guid":1234, "Counters":[2, 2, 1, 2]}]
+
+;--- message_pump.ll
+; This is a message pump: the loop never exits. This should result in an
+; assertion because we can't reach an exit BB
+
+define void @foo(i32 %t) !guid !0 {
+entry:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)  
+  br label %blk
+blk:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
+  %x = icmp eq i32 %t, 0
+  br i1 %x, label %blk, label %exit
+exit:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
+  ret void
+}
+!0 = !{i64 1234}
+
+;--- profile_pump.json
+[{"Guid":1234, "Counters":[2, 10, 0]}]
+
+;--- unreachable.ll
+; An unreachable block is reached, that's an error
+define void @foo(i32 %t) !guid !0 {
+entry:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 0)
+  br label %blk
+blk:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 1)
+  %x = icmp eq i32 %t, 0
+  br i1 %x, label %b1, label %exit
+b1:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 2)
+  unreachable
+exit:
+  call void @llvm.instrprof.increment(ptr @foo, i64 42, i32 42, i32 3)
+  ret void
+}
+!0 = !{i64 1234}
+
+;--- profile_unreachable.json
+[{"Guid":1234, "Counters":[2, 1, 1, 2]}]
\ No newline at end of file

Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

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

A couple of small comments but otherwise lgtm

const auto &BBInfo = getBBInfo(*BB);
bool Inserted = false;
bool HasAWayOut = false;
for (auto I = 0U; I < BB->getTerminator()->getNumSuccessors(); ++I) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this use succ_size as used above, for consistency? And maybe call that once and save the result.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer using this current API (getNumSuccessors) here, they should be the same, but this is "closer" to the API used below (BB->getTerminator()->getSuccessor).

@@ -0,0 +1,85 @@
; REQUIRES: asserts
; Check that the profile annotator works: we hit an exit and non-zero paths to
; already visited blocks are not disconsidered.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you are trying to say by "are not disconsidered" here, especially with the double-negative.

Copy link
Member Author

Choose a reason for hiding this comment

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

clarified.

@mtrofin mtrofin force-pushed the users/mtrofin/09-17-_ctx_prof_fix_profileannotator_alltakenpathsexit_ branch from 6d23eef to 1c6e49a Compare September 18, 2024 21:26
3 similar comments
@mtrofin mtrofin force-pushed the users/mtrofin/09-17-_ctx_prof_fix_profileannotator_alltakenpathsexit_ branch from 1c6e49a to bbb3ba0 Compare September 19, 2024 02:48
Copy link
Member Author

mtrofin commented Sep 19, 2024

Merge activity

  • Sep 19, 12:06 AM EDT: @mtrofin started a stack merge that includes this pull request via Graphite.
  • Sep 19, 12:08 AM EDT: @mtrofin merged this pull request with Graphite.

@mtrofin mtrofin merged commit ce9209f into main Sep 19, 2024
8 checks passed
@mtrofin mtrofin deleted the users/mtrofin/09-17-_ctx_prof_fix_profileannotator_alltakenpathsexit_ branch September 19, 2024 04:08
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 19, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-5 while building llvm at step 5 "build-unified-tree".

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

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
9.780 [4457/8/1433] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/SymbolSize.cpp.o
9.789 [4456/8/1434] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/TapiFile.cpp.o
9.801 [4455/8/1435] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/TapiUniversal.cpp.o
9.810 [4454/8/1436] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/MachOUniversalWriter.cpp.o
9.820 [4453/8/1437] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/WasmObjectFile.cpp.o
9.829 [4452/8/1438] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/WindowsMachineFlag.cpp.o
9.842 [4451/8/1439] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/WindowsResource.cpp.o
9.853 [4450/8/1440] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/XCOFFObjectFile.cpp.o
9.863 [4449/8/1441] Building CXX object lib/ObjectYAML/CMakeFiles/LLVMObjectYAML.dir/ArchiveEmitter.cpp.o
9.864 [4448/8/1442] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o
FAILED: lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /opt/homebrew/bin/ccache /usr/bin/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/Transforms/Instrumentation -I/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/lib/Transforms/Instrumentation -I/Users/buildbot/buildbot-root/aarch64-darwin/build/include -I/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include -isystem /opt/homebrew/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -O3 -DNDEBUG -std=c++17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o -MF lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o.d -o lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o -c /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
In file included from /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp:21:
In file included from /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h:15:
In file included from /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include/llvm/IR/PassManager.h:40:
In file included from /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include/llvm/ADT/DenseMap.h:25:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/algorithm:1752:
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__algorithm/copy_backward.h:98:68: error: invalid operands to binary expression ('llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>' and 'long')
      auto __iter        = std::__copy_backward<_AlgPolicy>(__last - __size, __last, __local_last).second;
                                                            ~~~~~~ ^ ~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__algorithm/copy_move_common.h:109:19: note: in instantiation of function template specialization 'std::__copy_backward_loop<std::_ClassicAlgPolicy>::operator()<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>, 0>' requested here
  auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first));
                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__algorithm/copy_move_common.h:133:15: note: in instantiation of function template specialization 'std::__unwrap_and_dispatch<std::__overload<std::__copy_backward_loop<std::_ClassicAlgPolicy>, std::__copy_backward_trivial>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>, 0>' requested here
  return std::__unwrap_and_dispatch<_Algorithm>(std::move(__first), std::move(__last), std::move(__out_first));
              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__algorithm/copy_backward.h:122:15: note: in instantiation of function template specialization 'std::__dispatch_copy_or_move<std::_ClassicAlgPolicy, std::__copy_backward_loop<std::_ClassicAlgPolicy>, std::__copy_backward_trivial, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>>' requested here
  return std::__dispatch_copy_or_move<_AlgPolicy, __copy_backward_loop<_AlgPolicy>, __copy_backward_trivial>(
              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__algorithm/copy_backward.h:135:15: note: in instantiation of function template specialization 'std::__copy_backward<std::_ClassicAlgPolicy, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>>' requested here
  return std::__copy_backward<_ClassicAlgPolicy>(
              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/deque:2186:20: note: in instantiation of function template specialization 'std::copy_backward<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>>' requested here
            _VSTD::copy_backward(__f, __m, __old_end);
                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/deque:2112:10: note: in instantiation of function template specialization 'std::deque<const llvm::BasicBlock *>::__insert_bidirectional<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>>' requested here
  return __insert_bidirectional(__p, __f, __l, std::distance(__f, __l));
         ^
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2100:5: note: in instantiation of function template specialization 'std::deque<const llvm::BasicBlock *>::insert<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>>' requested here
  C.insert(C.end(), adl_begin(R), adl_end(R));
    ^
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp:249:15: note: in instantiation of function template specialization 'llvm::append_range<std::deque<const llvm::BasicBlock *>, llvm::iterator_range<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>>>' requested here
        llvm::append_range(Worklist, successors(BB));
              ^
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include/llvm/ADT/APInt.h:2186:14: note: candidate function not viable: no known conversion from 'llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>' to 'APInt' for 1st argument
inline APInt operator-(APInt a, uint64_t RHS) {
             ^
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/include/llvm/ADT/APInt.h:2175:14: note: candidate function not viable: no known conversion from 'llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>' to 'APInt' for 1st argument
inline APInt operator-(APInt a, const APInt &b) {

@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 19, 2024

LLVM Buildbot has detected a new failure on builder flang-aarch64-libcxx running on linaro-flang-aarch64-libcxx while building llvm at step 5 "build-unified-tree".

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

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
34.774 [4412/13/2762] Building VectorOps.h.inc...
34.774 [4412/12/2763] Building VectorTransformOps.h.inc...
34.774 [4412/11/2764] Building Passes.h.inc...
34.774 [4412/10/2765] Building X86Vector.cpp.inc...
34.774 [4412/9/2766] Building X86Vector.h.inc...
34.775 [4412/8/2767] Building X86VectorDialect.cpp.inc...
34.775 [4412/7/2768] Building X86VectorDialect.h.inc...
34.775 [4412/6/2769] Building X86VectorTypes.cpp.inc...
38.402 [4412/5/2770] Building CXX object lib/Object/CMakeFiles/LLVMObject.dir/IRSymtab.cpp.o
39.033 [4412/4/2771] Building CXX object lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o
FAILED: lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/lib/Transforms/Instrumentation -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/lib/Transforms/Instrumentation -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/include -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fPIC  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o -MF lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o.d -o lib/Transforms/Instrumentation/CMakeFiles/LLVMInstrumentation.dir/PGOCtxProfFlattening.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-libcxx/llvm-project/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp
In file included from ../llvm-project/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp:21:
In file included from ../llvm-project/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h:15:
In file included from ../llvm-project/llvm/include/llvm/IR/PassManager.h:40:
In file included from ../llvm-project/llvm/include/llvm/ADT/DenseMap.h:25:
In file included from /usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/algorithm:1795:
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/__algorithm/copy_backward.h:98:68: error: invalid operands to binary expression ('llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>' and 'long')
   98 |       auto __iter        = std::__copy_backward<_AlgPolicy>(__last - __size, __last, __local_last).second;
      |                                                             ~~~~~~ ^ ~~~~~~
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/__algorithm/copy_move_common.h:109:19: note: in instantiation of function template specialization 'std::__copy_backward_loop<std::_ClassicAlgPolicy>::operator()<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>, 0>' requested here
  109 |   auto __result = _Algorithm()(std::move(__range.first), std::move(__range.second), std::__unwrap_iter(__out_first));
      |                   ^
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/__algorithm/copy_move_common.h:133:15: note: in instantiation of function template specialization 'std::__unwrap_and_dispatch<std::__overload<std::__copy_backward_loop<std::_ClassicAlgPolicy>, std::__copy_backward_trivial>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>, 0>' requested here
  133 |   return std::__unwrap_and_dispatch<_Algorithm>(std::move(__first), std::move(__last), std::move(__out_first));
      |               ^
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/__algorithm/copy_backward.h:121:15: note: in instantiation of function template specialization 'std::__dispatch_copy_or_move<std::_ClassicAlgPolicy, std::__copy_backward_loop<std::_ClassicAlgPolicy>, std::__copy_backward_trivial, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>>' requested here
  121 |   return std::__dispatch_copy_or_move<_AlgPolicy, __copy_backward_loop<_AlgPolicy>, __copy_backward_trivial>(
      |               ^
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/__algorithm/copy_backward.h:132:15: note: in instantiation of function template specialization 'std::__copy_backward<std::_ClassicAlgPolicy, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>>' requested here
  132 |   return std::__copy_backward<_ClassicAlgPolicy>(std::move(__first), std::move(__last), std::move(__result)).second;
      |               ^
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/deque:1929:12: note: in instantiation of function template specialization 'std::copy_backward<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, std::__deque_iterator<const llvm::BasicBlock *, const llvm::BasicBlock **, const llvm::BasicBlock *&, const llvm::BasicBlock ***, long>>' requested here
 1929 |       std::copy_backward(__f, __m, __old_end);
      |            ^
/usr/local/clang+llvm-18.1.8-aarch64-linux-gnu/bin/../include/c++/v1/deque:1865:10: note: in instantiation of function template specialization 'std::deque<const llvm::BasicBlock *>::__insert_bidirectional<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>>' requested here
 1865 |   return __insert_bidirectional(__p, __f, __l, std::distance(__f, __l));
      |          ^
../llvm-project/llvm/include/llvm/ADT/STLExtras.h:2100:5: note: in instantiation of function template specialization 'std::deque<const llvm::BasicBlock *>::insert<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>, 0>' requested here
 2100 |   C.insert(C.end(), adl_begin(R), adl_end(R));
      |     ^
../llvm-project/llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp:249:15: note: in instantiation of function template specialization 'llvm::append_range<std::deque<const llvm::BasicBlock *>, llvm::iterator_range<llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>>>' requested here
  249 |         llvm::append_range(Worklist, successors(BB));
      |               ^
../llvm-project/llvm/include/llvm/ADT/APInt.h:2186:14: note: candidate function not viable: no known conversion from 'llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>' to 'APInt' for 1st argument
 2186 | inline APInt operator-(APInt a, uint64_t RHS) {
      |              ^         ~~~~~~~
../llvm-project/llvm/include/llvm/ADT/APInt.h:2175:14: note: candidate function not viable: no known conversion from 'llvm::SuccIterator<const llvm::Instruction, const llvm::BasicBlock>' to 'APInt' for 1st argument
 2175 | inline APInt operator-(APInt a, const APInt &b) {

tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
Added tests to the validator and fixed issues stemming from the previous skipping over BBs with single successors - which is incorrect. That would be now picked by added tests where the assertions are expected to be triggered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis llvm:transforms PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants