1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -simplifycfg -S | FileCheck -enable-var-scope %s
4 ; Test basic folding to a conditional branch.
5 define i32 @foo(i64 %x, i64 %y) nounwind {
8 ; CHECK-NEXT: [[EQ:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
9 ; CHECK-NEXT: br i1 [[EQ]], label [[B:%.*]], label [[SWITCH:%.*]]
11 ; CHECK-NEXT: [[LT:%.*]] = icmp slt i64 [[X]], [[Y]]
12 ; CHECK-NEXT: br i1 [[LT]], label [[A:%.*]], label [[B]]
14 ; CHECK-NEXT: tail call void @bees.a() #0
15 ; CHECK-NEXT: ret i32 1
17 ; CHECK-NEXT: [[RETVAL:%.*]] = phi i32 [ 0, [[SWITCH]] ], [ 2, [[ENTRY:%.*]] ]
18 ; CHECK-NEXT: tail call void @bees.b() #0
19 ; CHECK-NEXT: ret i32 [[RETVAL]]
22 %eq = icmp eq i64 %x, %y
23 br i1 %eq, label %b, label %switch
25 %lt = icmp slt i64 %x, %y
26 %qux = select i1 %lt, i32 0, i32 2
27 switch i32 %qux, label %bees [
33 tail call void @bees.a() nounwind
36 %retval = phi i32 [0, %switch], [0, %switch], [2, %entry]
37 tail call void @bees.b() nounwind
40 tail call void @llvm.trap() nounwind
44 ; Test basic folding to an unconditional branch.
45 define i32 @bar(i64 %x, i64 %y) nounwind {
48 ; CHECK-NEXT: tail call void @bees.a() #0
49 ; CHECK-NEXT: ret i32 0
52 %lt = icmp slt i64 %x, %y
53 %qux = select i1 %lt, i32 0, i32 2
54 switch i32 %qux, label %bees [
60 %retval = phi i32 [0, %entry], [0, %entry], [1, %b]
61 tail call void @bees.a() nounwind
64 tail call void @bees.b() nounwind
67 tail call void @llvm.trap() nounwind
71 ; Test the edge case where both values from the select are the default case.
72 define void @bazz(i64 %x, i64 %y) nounwind {
75 ; CHECK-NEXT: tail call void @bees.b() #0
76 ; CHECK-NEXT: ret void
79 %lt = icmp slt i64 %x, %y
80 %qux = select i1 %lt, i32 10, i32 12
81 switch i32 %qux, label %b [
87 tail call void @bees.a() nounwind
90 tail call void @bees.b() nounwind
93 tail call void @llvm.trap()
97 ; Test the edge case where both values from the select are equal.
98 define void @quux(i64 %x, i64 %y) nounwind {
101 ; CHECK-NEXT: tail call void @bees.a() #0
102 ; CHECK-NEXT: ret void
105 %lt = icmp slt i64 %x, %y
106 %qux = select i1 %lt, i32 0, i32 0
107 switch i32 %qux, label %b [
113 tail call void @bees.a() nounwind
116 tail call void @bees.b() nounwind
119 tail call void @llvm.trap()
123 ; A final test, for phi node munging.
124 define i32 @xyzzy(i64 %x, i64 %y) {
125 ; CHECK-LABEL: @xyzzy(
127 ; CHECK-NEXT: [[EQ:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
128 ; CHECK-NEXT: [[LT:%.*]] = icmp slt i64 [[X]], [[Y]]
129 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[LT]], i32 -1, i32 1
130 ; CHECK-NEXT: [[VAL:%.*]] = select i1 [[EQ]], i32 0, i32 [[SPEC_SELECT]]
131 ; CHECK-NEXT: ret i32 [[VAL]]
134 %eq = icmp eq i64 %x, %y
135 br i1 %eq, label %r, label %cont
137 %lt = icmp slt i64 %x, %y
138 %qux = select i1 %lt, i32 0, i32 2
139 switch i32 %qux, label %bees [
145 %val = phi i32 [0, %entry], [1, %cont], [1, %cont]
150 tail call void @llvm.trap()
154 declare void @llvm.trap() nounwind noreturn
155 declare void @bees.a() nounwind
156 declare void @bees.b() nounwind
158 ; CHECK: attributes #1 = { cold noreturn nounwind }