1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -jump-threading -S < %s | FileCheck %s
3
4declare void @f()
5declare void @f2()
6declare void @f3()
7
8; br on cond.fr should be removed & ENTRY -> A -> B should be threaded
9define i32 @simple(i1 %cond) {
10; CHECK-LABEL: @simple(
11; CHECK-NEXT:  ENTRY:
12; CHECK-NEXT:    br i1 [[COND:%.*]], label [[B:%.*]], label [[EXIT:%.*]]
13; CHECK:       B:
14; CHECK-NEXT:    call void @f()
15; CHECK-NEXT:    ret i32 1
16; CHECK:       EXIT:
17; CHECK-NEXT:    ret i32 0
18;
19ENTRY:
20  %cond.fr = freeze i1 %cond
21  br i1 %cond, label %A, label %EXIT
22A:
23  br i1 %cond.fr, label %B, label %EXIT
24B:
25  call void @f()
26  ret i32 1
27EXIT:
28  ret i32 0
29}
30
31define void @switch(i32 %cond) {
32; CHECK-LABEL: @switch(
33; CHECK-NEXT:  ENTRY:
34; CHECK-NEXT:    [[COND_FR:%.*]] = freeze i32 [[COND:%.*]]
35; CHECK-NEXT:    switch i32 [[COND]], label [[DEFAULT:%.*]] [
36; CHECK-NEXT:    i32 0, label [[A_TAKEN:%.*]]
37; CHECK-NEXT:    i32 1, label [[B_TAKEN:%.*]]
38; CHECK-NEXT:    ]
39; CHECK:       DEFAULT:
40; CHECK-NEXT:    switch i32 [[COND_FR]], label [[PRESERVED1:%.*]] [
41; CHECK-NEXT:    i32 0, label [[PRESERVED2:%.*]]
42; CHECK-NEXT:    ]
43; CHECK:       PRESERVED1:
44; CHECK-NEXT:    call void @f()
45; CHECK-NEXT:    ret void
46; CHECK:       PRESERVED2:
47; CHECK-NEXT:    call void @f2()
48; CHECK-NEXT:    ret void
49; CHECK:       A_TAKEN:
50; CHECK-NEXT:    call void @f()
51; CHECK-NEXT:    ret void
52; CHECK:       B_TAKEN:
53; CHECK-NEXT:    call void @f()
54; CHECK-NEXT:    ret void
55;
56ENTRY:
57  %cond.fr = freeze i32 %cond
58  switch i32 %cond, label %DEFAULT [
59  i32 0, label %A
60  i32 1, label %B
61  ]
62DEFAULT:
63  switch i32 %cond.fr, label %PRESERVED1 [
64  i32 0, label %PRESERVED2
65  ]
66PRESERVED1:
67  call void @f()
68  ret void
69PRESERVED2:
70  call void @f2()
71  ret void
72
73A:
74  switch i32 %cond.fr, label %A_NOTTAKEN [
75  i32 0, label %A_TAKEN
76  ]
77A_TAKEN:
78  call void @f()
79  ret void
80A_NOTTAKEN:
81  call void @f2()
82  ret void
83
84B:
85  switch i32 %cond.fr, label %B_TAKEN [
86  i32 0, label %B_NOTTAKEN
87  ]
88B_TAKEN:
89  call void @f()
90  ret void
91B_NOTTAKEN:
92  call void @f2()
93  ret void
94}
95