[PATCH] D154922: [BOLT] fix the endless loop of --iterative-guess
yinchengwu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 21:00:44 PDT 2023
maipianworni updated this revision to Diff 540636.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154922/new/
https://reviews.llvm.org/D154922
Files:
bolt/lib/Passes/MCF.cpp
bolt/test/Inputs/guess.c
bolt/test/Inputs/guess.fdata
bolt/test/iterative-guess.test
Index: bolt/test/iterative-guess.test
===================================================================
--- /dev/null
+++ bolt/test/iterative-guess.test
@@ -0,0 +1,7 @@
+# Check that bolt will not fall in the endless loop when using
+# the fdata file in case of enabling iterative-guess option.
+# The fdata file is generated based on aarch64, this test need to
+# be run in aarch64 to make sense
+
+RUN: %clang %cflags %S/Inputs/guess.c -o %t.exe
+RUN: llvm-bolt %t.exe -o %t -data=%S/Inputs/guess.fdata --iterative-guess
Index: bolt/test/Inputs/guess.fdata
===================================================================
--- /dev/null
+++ bolt/test/Inputs/guess.fdata
@@ -0,0 +1,8 @@
+no_lbr cycles:u:
+1 test 20 12
+1 test c 5778
+1 test 30 5494
+1 test 8 1
+1 main 34 15379
+1 main 44 12401
+1 main 38 16433
Index: bolt/test/Inputs/guess.c
===================================================================
--- /dev/null
+++ bolt/test/Inputs/guess.c
@@ -0,0 +1,28 @@
+// Verify that bolt will not fall in the endless loop when using
+// the fdata file in case of enabling iterative-guess option.
+
+// RUN: %clang %cflags %p/Inputs/guess.c -o %t.exe
+// RUN: llvm-bolt %t.exe -o %t -data=%p/Inputs/guess.fdata --iterative-guess
+
+// The problem arises in the following situation
+// BB0 -- BB1 BB0 -> BB1
+// \ | BB1 -> BB2
+// \ | BB0 -> BB2
+// \ |
+// BB2
+
+int test(int a, int b) {
+ if (b == 1) {
+ a = b + 1;
+ }
+ return a;
+}
+
+int main() {
+ long long i = 5000000000;
+ while (i > 0) {
+ test(2, 1);
+ i--;
+ }
+ return 0;
+}
Index: bolt/lib/Passes/MCF.cpp
===================================================================
--- bolt/lib/Passes/MCF.cpp
+++ bolt/lib/Passes/MCF.cpp
@@ -264,6 +264,7 @@
continue;
Pred->getBranchInfo(*BB).Count = Guessed;
+ GuessedArcs.insert(std::make_pair(Pred, BB));
return true;
}
llvm_unreachable("Expected unguessed arc");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154922.540636.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230715/e7b5556f/attachment.bin>
More information about the llvm-commits
mailing list