1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
6 define i32 @basic(i32 %x) {
9 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -5
10 ; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[X_OFF]], 3
11 ; CHECK-NEXT: br i1 [[SWITCH]], label [[A:%.*]], label [[DEFAULT:%.*]]
13 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[TMP0:%.*]], [[DEFAULT]] ], [ [[TMP1:%.*]], [[A]] ]
14 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
16 ; CHECK-NEXT: [[TMP0]] = call i32 @f(i32 0)
17 ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
19 ; CHECK-NEXT: [[TMP1]] = call i32 @f(i32 1)
20 ; CHECK-NEXT: br label [[COMMON_RET]]
24 switch i32 %x, label %default [
30 %0 = call i32 @f(i32 0)
33 %1 = call i32 @f(i32 1)
38 define i32 @unreachable(i32 %x) {
39 ; CHECK-LABEL: @unreachable(
41 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -5
42 ; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[X_OFF]], 3
43 ; CHECK-NEXT: br i1 [[SWITCH]], label [[A:%.*]], label [[B:%.*]]
45 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[TMP0:%.*]], [[A]] ], [ [[TMP1:%.*]], [[B]] ]
46 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
48 ; CHECK-NEXT: [[TMP0]] = call i32 @f(i32 0)
49 ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
51 ; CHECK-NEXT: [[TMP1]] = call i32 @f(i32 1)
52 ; CHECK-NEXT: br label [[COMMON_RET]]
56 switch i32 %x, label %unreachable [
68 %0 = call i32 @f(i32 0)
71 %1 = call i32 @f(i32 1)
76 define i32 @unreachable2(i32 %x) {
77 ; CHECK-LABEL: @unreachable2(
79 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -5
80 ; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[X_OFF]], 3
81 ; CHECK-NEXT: br i1 [[SWITCH]], label [[A:%.*]], label [[B:%.*]]
83 ; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = phi i32 [ [[TMP0:%.*]], [[A]] ], [ [[TMP1:%.*]], [[B]] ]
84 ; CHECK-NEXT: ret i32 [[COMMON_RET_OP]]
86 ; CHECK-NEXT: [[TMP0]] = call i32 @f(i32 0)
87 ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
89 ; CHECK-NEXT: [[TMP1]] = call i32 @f(i32 1)
90 ; CHECK-NEXT: br label [[COMMON_RET]]
94 ; Note: folding the most popular case destination into the default
95 ; would prevent switch-to-icmp here.
96 switch i32 %x, label %unreachable [
106 %0 = call i32 @f(i32 0)
109 %1 = call i32 @f(i32 1)
113 ; This would crash because we did not clean up the
114 ; default block of the switch before removing the switch.
116 define void @PR42737(i32* %a, i1 %c) {
117 ; CHECK-LABEL: @PR42737(
119 ; CHECK-NEXT: unreachable
122 br i1 %c, label %switch, label %else
129 %cleanup.dest1 = phi i32 [ 0, %else ], [ 3, %entry ]
130 switch i32 %cleanup.dest1, label %unreach1 [
131 i32 0, label %cleanup1
132 i32 3, label %cleanup2
142 %phi2 = phi i32 [ %cleanup.dest1, %switch ]