summaryrefslogtreecommitdiffstats
path: root/clang/test/Profile/c-unprofiled-blocks.c
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-04-04 02:48:51 +0000
committerJustin Bogner <mail@justinbogner.com>2014-04-04 02:48:51 +0000
commitf3aefca7c1bcdd3a6445b7ae04a9f69af567a7e7 (patch)
treec218bc20650b5f7f7d4f26c1fa4870c56aaab52c /clang/test/Profile/c-unprofiled-blocks.c
parent08d57b951c2ff9c5f710d4f66e71393cee573733 (diff)
downloadbcm5719-llvm-f3aefca7c1bcdd3a6445b7ae04a9f69af567a7e7.tar.gz
bcm5719-llvm-f3aefca7c1bcdd3a6445b7ae04a9f69af567a7e7.zip
CodeGen: Don't create branch weight metadata from empty profiles
If all of our weights are zero when calculating branch weights, it means we haven't profiled the code in question. Avoid creating a metadata node that says all branches are equally likely in this case. The test also checks constructs that hit the other createBranchWeights overload. These were already working. llvm-svn: 205606
Diffstat (limited to 'clang/test/Profile/c-unprofiled-blocks.c')
-rw-r--r--clang/test/Profile/c-unprofiled-blocks.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/clang/test/Profile/c-unprofiled-blocks.c b/clang/test/Profile/c-unprofiled-blocks.c
new file mode 100644
index 00000000000..1f75a0da47f
--- /dev/null
+++ b/clang/test/Profile/c-unprofiled-blocks.c
@@ -0,0 +1,68 @@
+// Blocks that we have no profile data for (ie, it was never reached in training
+// runs) shouldn't have any branch weight metadata added.
+
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-unprofiled-blocks.c %s -o - -emit-llvm -fprofile-instr-use=%S/Inputs/c-unprofiled-blocks.profdata | FileCheck -check-prefix=PGOUSE %s
+
+// PGOUSE-LABEL: @never_called(i32 %i)
+int never_called(int i) {
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ if (i) {}
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ for (i = 0; i < 100; ++i) {
+ }
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ while (--i) {}
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ do {} while (i++ < 75);
+
+ // PGOUSE: switch {{.*}} [
+ // PGOUSE-NEXT: i32 12
+ // PGOUSE-NEXT: i32 82
+ // PGOUSE-NEXT: ]{{$}}
+ switch (i) {
+ case 12: return 3;
+ case 82: return 0;
+ default: return 89;
+ }
+}
+
+// PGOUSE-LABEL: @dead_code(i32 %i)
+int dead_code(int i) {
+ // PGOUSE: br {{.*}}, !prof !{{[0-9]+}}
+ if (i) {
+ // This branch is never reached.
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ if (!i) {}
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ for (i = 0; i < 100; ++i) {
+ }
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ while (--i) {}
+
+ // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+ do {} while (i++ < 75);
+
+ // PGOUSE: switch {{.*}} [
+ // PGOUSE-NEXT: i32 12
+ // PGOUSE-NEXT: i32 82
+ // PGOUSE-NEXT: ]{{$}}
+ switch (i) {
+ case 12: return 3;
+ case 82: return 0;
+ default: return 89;
+ }
+ }
+ return 2;
+}
+
+// PGOUSE-LABEL: @main(i32 %argc, i8** %argv)
+int main(int argc, const char *argv[]) {
+ dead_code(0);
+ return 0;
+}
OpenPOWER on IntegriCloud