1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
5 declare i1 @uniform_result(i1 %c)
7 define void @dont_merge_cbranches1(i32 %V) {
8 ; CHECK-LABEL: @dont_merge_cbranches1(
9 ; CHECK-NEXT: [[DIVERGENT_COND:%.*]] = icmp ne i32 [[V:%.*]], 0
10 ; CHECK-NEXT: [[UNIFORM_COND:%.*]] = call i1 @uniform_result(i1 [[DIVERGENT_COND]])
11 ; CHECK-NEXT: br i1 [[UNIFORM_COND]], label [[BB2:%.*]], label [[EXIT:%.*]], !prof [[PROF0:![0-9]+]]
13 ; CHECK-NEXT: br i1 [[DIVERGENT_COND]], label [[BB3:%.*]], label [[EXIT]]
15 ; CHECK-NEXT: call void @bar()
16 ; CHECK-NEXT: br label [[EXIT]]
18 ; CHECK-NEXT: ret void
20 %divergent_cond = icmp ne i32 %V, 0
21 %uniform_cond = call i1 @uniform_result(i1 %divergent_cond)
22 br i1 %uniform_cond, label %bb2, label %exit, !prof !0
24 br i1 %divergent_cond, label %bb3, label %exit
32 define void @dont_merge_cbranches2(i32 %V) {
33 ; CHECK-LABEL: @dont_merge_cbranches2(
34 ; CHECK-NEXT: [[DIVERGENT_COND:%.*]] = icmp ne i32 [[V:%.*]], 0
35 ; CHECK-NEXT: [[UNIFORM_COND:%.*]] = call i1 @uniform_result(i1 [[DIVERGENT_COND]])
36 ; CHECK-NEXT: br i1 [[UNIFORM_COND]], label [[EXIT:%.*]], label [[BB2:%.*]], !prof [[PROF1:![0-9]+]]
38 ; CHECK-NEXT: br i1 [[DIVERGENT_COND]], label [[BB3:%.*]], label [[EXIT]]
40 ; CHECK-NEXT: call void @bar()
41 ; CHECK-NEXT: br label [[EXIT]]
43 ; CHECK-NEXT: ret void
45 %divergent_cond = icmp ne i32 %V, 0
46 %uniform_cond = call i1 @uniform_result(i1 %divergent_cond)
47 br i1 %uniform_cond, label %exit, label %bb2, !prof !1
49 br i1 %divergent_cond, label %bb3, label %exit
57 define void @merge_cbranches(i32 %V) {
58 ; CHECK-LABEL: @merge_cbranches(
59 ; CHECK-NEXT: [[DIVERGENT_COND:%.*]] = icmp ne i32 [[V:%.*]], 0
60 ; CHECK-NEXT: [[UNIFORM_COND:%.*]] = call i1 @uniform_result(i1 [[DIVERGENT_COND]])
61 ; CHECK-NEXT: [[DIVERGENT_COND_NOT:%.*]] = xor i1 [[DIVERGENT_COND]], true
62 ; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[UNIFORM_COND]], i1 true, i1 [[DIVERGENT_COND_NOT]]
63 ; CHECK-NEXT: br i1 [[BRMERGE]], label [[EXIT:%.*]], label [[BB3:%.*]], !prof [[PROF2:![0-9]+]]
65 ; CHECK-NEXT: call void @bar()
66 ; CHECK-NEXT: br label [[EXIT]]
68 ; CHECK-NEXT: ret void
70 %divergent_cond = icmp ne i32 %V, 0
71 %uniform_cond = call i1 @uniform_result(i1 %divergent_cond)
72 br i1 %uniform_cond, label %exit, label %bb2, !prof !2
74 br i1 %divergent_cond, label %bb3, label %exit
82 define void @uint32_overflow_test(i1 %arg, i1 %arg1) {
83 ; CHECK-LABEL: @uint32_overflow_test(
85 ; CHECK-NEXT: [[BRMERGE:%.*]] = select i1 [[ARG:%.*]], i1 true, i1 [[ARG1:%.*]]
86 ; CHECK-NEXT: ret void
89 br i1 %arg, label %bb4, label %bb2, !prof !3
92 br i1 %arg1, label %bb4, label %bb3
101 !0 = !{!"branch_weights", i32 1, i32 1000}
102 !1 = !{!"branch_weights", i32 1000, i32 1}
103 !2 = !{!"branch_weights", i32 3, i32 2}
104 !3 = !{!"branch_weights", i32 -258677585, i32 -1212131848}