Add a test case for the fix of profile update issue when lowering switch statement.
authorCong Hou <congh@google.com>
Wed, 23 Sep 2015 00:34:56 +0000 (00:34 +0000)
committerCong Hou <congh@google.com>
Wed, 23 Sep 2015 00:34:56 +0000 (00:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248356 91177308-0d34-0410-b5e6-96231b3b80d8

test/CodeGen/X86/switch-edge-weight.ll

index 27f15a766723028a576f09209f1ba0c3699a9d56..d93bfb61047a1c99c92cfc8ab66927e37876551d 100644 (file)
@@ -224,6 +224,58 @@ sw.epilog:
 ; CHECK: Successors according to CFG: BB#2(30) BB#3(20)
 }
 
+; CHECK-LABEL: test5
+
+define void @test5(i32 %x) nounwind {
+entry:
+
+; In this switch statement, there is an edge from jump table to default basic
+; block.
+
+  switch i32 %x, label %sw.default [
+    i32 1, label %sw.bb
+    i32 5, label %sw.bb2
+    i32 7, label %sw.bb3
+    i32 9, label %sw.bb4
+    i32 31, label %sw.bb5
+  ], !prof !2
+
+sw.bb:
+  call void @foo(i32 0)
+  br label %sw.epilog
+
+sw.bb2:
+  call void @foo(i32 1)
+  br label %sw.epilog
+
+sw.bb3:
+  call void @foo(i32 2)
+  br label %sw.epilog
+
+sw.bb4:
+  call void @foo(i32 3)
+  br label %sw.epilog
+
+sw.bb5:
+  call void @foo(i32 4)
+  br label %sw.epilog
+
+sw.default:
+  call void @foo(i32 5)
+  br label %sw.epilog
+
+sw.epilog:
+  ret void
+
+; Check if weights are correctly assigned to edges generated from switch
+; statement.
+;
+; CHECK: BB#0:
+; BB#0 to BB#6: [10, UINT32_MAX] (15)
+; BB#0 to BB#8: [1, 5, 7, 9] (jump table) (45)
+; CHECK: Successors according to CFG: BB#8(15) BB#9(45)
+}
+
 !1 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10} 
 !2 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10} 
 !3 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}