• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -loop-unswitch -loop-unswitch-with-block-frequency -S 2>&1 | FileCheck %s
2
3;; trivial condition should be unswithed regardless of coldness.
4define i32 @test1(i1 %cond1, i1 %cond2) !prof !1 {
5  br i1 %cond1, label %loop_begin, label %loop_exit, !prof !0
6
7loop_begin:
8; CHECK: br i1 true, label %continue, label %loop_exit.loopexit
9  br i1 %cond2, label %continue, label %loop_exit  ; trivial condition
10
11continue:
12  call void @some_func1() noreturn nounwind
13  br label %loop_begin
14
15loop_exit:
16  ret i32 0
17}
18
19;; cold non-trivial condition should not be unswitched.
20define i32 @test2(i32* %var, i1 %cond1, i1 %cond2) !prof !1 {
21  br i1 %cond1, label %loop_begin, label %loop_exit, !prof !0
22
23loop_begin:
24  store i32 1, i32* %var
25; CHECK: br i1 %cond2, label %continue1, label %continue2
26  br i1 %cond2, label %continue1, label %continue2  ; non-trivial condition
27
28continue1:
29  call void @some_func1() noreturn nounwind
30  br label %joint
31
32continue2:
33  call void @some_func2() noreturn nounwind
34  br label %joint
35
36joint:
37;; unswitching will duplicate these calls.
38  call void @some_func3() noreturn nounwind
39  call void @some_func4() noreturn nounwind
40  br label %loop_begin
41
42loop_exit:
43  ret i32 0
44}
45
46declare void @some_func1() noreturn
47declare void @some_func2() noreturn
48declare void @some_func3() noreturn
49declare void @some_func4() noreturn
50
51!0 = !{!"branch_weights", i32 1, i32 100000000}
52!1 = !{!"function_entry_count", i64 100}
53