1 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
3 ; Test basic folding to a conditional branch.
4 define i32 @foo(i64 %x, i64 %y) nounwind {
7 %eq = icmp eq i64 %x, %y
8 br i1 %eq, label %b, label %switch
10 %lt = icmp slt i64 %x, %y
11 ; CHECK: br i1 %lt, label %a, label %b
12 %qux = select i1 %lt, i32 0, i32 2
13 switch i32 %qux, label %bees [
19 tail call void @bees.a() nounwind
22 ; CHECK-NEXT: %retval = phi i32 [ 0, %switch ], [ 2, %entry ]
24 %retval = phi i32 [0, %switch], [0, %switch], [2, %entry]
25 tail call void @bees.b() nounwind
29 tail call void @llvm.trap() nounwind
33 ; Test basic folding to an unconditional branch.
34 define i32 @bar(i64 %x, i64 %y) nounwind {
38 ; CHECK-NEXT: tail call void @bees.a() nounwind
39 ; CHECK-NEXT: ret i32 0
40 %lt = icmp slt i64 %x, %y
41 %qux = select i1 %lt, i32 0, i32 2
42 switch i32 %qux, label %bees [
48 %retval = phi i32 [0, %entry], [0, %entry], [1, %b]
49 tail call void @bees.a() nounwind
52 tail call void @bees.b() nounwind
55 tail call void @llvm.trap() nounwind
59 ; Test the edge case where both values from the select are the default case.
60 define void @bazz(i64 %x, i64 %y) nounwind {
64 ; CHECK-NEXT: tail call void @bees.b() nounwind
65 ; CHECK-NEXT: ret void
66 %lt = icmp slt i64 %x, %y
67 %qux = select i1 %lt, i32 10, i32 12
68 switch i32 %qux, label %b [
74 tail call void @bees.a() nounwind
77 tail call void @bees.b() nounwind
80 tail call void @llvm.trap()
84 ; Test the edge case where both values from the select are equal.
85 define void @quux(i64 %x, i64 %y) nounwind {
89 ; CHECK-NEXT: tail call void @bees.a() nounwind
90 ; CHECK-NEXT: ret void
91 %lt = icmp slt i64 %x, %y
92 %qux = select i1 %lt, i32 0, i32 0
93 switch i32 %qux, label %b [
99 tail call void @bees.a() nounwind
102 tail call void @bees.b() nounwind
105 tail call void @llvm.trap()
109 ; A final test, for phi node munging.
110 define i32 @xyzzy(i64 %x, i64 %y) {
113 %eq = icmp eq i64 %x, %y
114 br i1 %eq, label %r, label %cont
116 ; CHECK: %lt = icmp slt i64 %x, %y
117 %lt = icmp slt i64 %x, %y
118 ; CHECK-NEXT: br i1 %lt, label %a, label %r
119 %qux = select i1 %lt, i32 0, i32 2
120 switch i32 %qux, label %bees [
126 %val = phi i32 [0, %entry], [1, %cont], [1, %cont]
132 tail call void @llvm.trap()
136 declare void @llvm.trap() nounwind noreturn
137 declare void @bees.a() nounwind
138 declare void @bees.b() nounwind