1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %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: [[COMMON_RET_OP:%.*]] = phi i32 [ 1, [[A]] ], [ [[RETVAL:%.*]], [[B]] ]
15 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
17 ; CHECK-NEXT: tail call void @bees.a() #[[ATTR0:[0-9]+]]
18 ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
20 ; CHECK-NEXT: [[RETVAL]] = phi i32 [ 0, [[SWITCH]] ], [ 2, [[ENTRY:%.*]] ]
21 ; CHECK-NEXT: tail call void @bees.b() #[[ATTR0]]
22 ; CHECK-NEXT: br label [[COMMON_RET]]
25 %eq = icmp eq i64 %x, %y
26 br i1 %eq, label %b, label %switch
28 %lt = icmp slt i64 %x, %y
29 %qux = select i1 %lt, i32 0, i32 2
30 switch i32 %qux, label %bees [
36 tail call void @bees.a() nounwind
39 %retval = phi i32 [0, %switch], [0, %switch], [2, %entry]
40 tail call void @bees.b() nounwind
43 tail call void @llvm.trap() nounwind
47 ; Test basic folding to an unconditional branch.
48 define i32 @bar(i64 %x, i64 %y) nounwind {
51 ; CHECK-NEXT: tail call void @bees.a() #[[ATTR0]]
52 ; CHECK-NEXT: ret i32 0
55 %lt = icmp slt i64 %x, %y
56 %qux = select i1 %lt, i32 0, i32 2
57 switch i32 %qux, label %bees [
63 %retval = phi i32 [0, %entry], [0, %entry], [1, %b]
64 tail call void @bees.a() nounwind
67 tail call void @bees.b() nounwind
70 tail call void @llvm.trap() nounwind
74 ; Test the edge case where both values from the select are the default case.
75 define void @bazz(i64 %x, i64 %y) nounwind {
78 ; CHECK-NEXT: tail call void @bees.b() #[[ATTR0]]
79 ; CHECK-NEXT: ret void
82 %lt = icmp slt i64 %x, %y
83 %qux = select i1 %lt, i32 10, i32 12
84 switch i32 %qux, label %b [
90 tail call void @bees.a() nounwind
93 tail call void @bees.b() nounwind
96 tail call void @llvm.trap()
100 ; Test the edge case where both values from the select are equal.
101 define void @quux(i64 %x, i64 %y) nounwind {
102 ; CHECK-LABEL: @quux(
104 ; CHECK-NEXT: tail call void @bees.a() #[[ATTR0]]
105 ; CHECK-NEXT: ret void
108 %lt = icmp slt i64 %x, %y
109 %qux = select i1 %lt, i32 0, i32 0
110 switch i32 %qux, label %b [
116 tail call void @bees.a() nounwind
119 tail call void @bees.b() nounwind
122 tail call void @llvm.trap()
126 ; A final test, for phi node munging.
127 define i32 @xyzzy(i64 %x, i64 %y) {
128 ; CHECK-LABEL: @xyzzy(
130 ; CHECK-NEXT: [[EQ:%.*]] = icmp eq i64 [[X:%.*]], [[Y:%.*]]
131 ; CHECK-NEXT: [[LT:%.*]] = icmp slt i64 [[X]], [[Y]]
132 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[LT]], i32 -1, i32 1
133 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = select i1 [[EQ]], i32 0, i32 [[SPEC_SELECT]]
134 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
137 %eq = icmp eq i64 %x, %y
138 br i1 %eq, label %r, label %cont
140 %lt = icmp slt i64 %x, %y
141 %qux = select i1 %lt, i32 0, i32 2
142 switch i32 %qux, label %bees [
148 %val = phi i32 [0, %entry], [1, %cont], [1, %cont]
153 tail call void @llvm.trap()
157 declare void @llvm.trap() nounwind noreturn
158 declare void @bees.a() nounwind
159 declare void @bees.b() nounwind
161 ; CHECK: attributes #1 = { cold noreturn nounwind memory(inaccessiblemem: write) }