1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -simplifycfg -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: [[TMP0:%.*]] = call i32 @f(i32 0)
14 ; CHECK-NEXT: ret i32 [[TMP0]]
16 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @f(i32 1)
17 ; CHECK-NEXT: ret i32 [[TMP1]]
21 switch i32 %x, label %default [
27 %0 = call i32 @f(i32 0)
30 %1 = call i32 @f(i32 1)
35 define i32 @unreachable(i32 %x) {
36 ; CHECK-LABEL: @unreachable(
38 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -5
39 ; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[X_OFF]], 3
40 ; CHECK-NEXT: br i1 [[SWITCH]], label [[A:%.*]], label [[B:%.*]]
42 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @f(i32 0)
43 ; CHECK-NEXT: ret i32 [[TMP0]]
45 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @f(i32 1)
46 ; CHECK-NEXT: ret i32 [[TMP1]]
50 switch i32 %x, label %unreachable [
62 %0 = call i32 @f(i32 0)
65 %1 = call i32 @f(i32 1)
70 define i32 @unreachable2(i32 %x) {
71 ; CHECK-LABEL: @unreachable2(
73 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X:%.*]], -5
74 ; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i32 [[X_OFF]], 3
75 ; CHECK-NEXT: br i1 [[SWITCH]], label [[A:%.*]], label [[B:%.*]]
77 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @f(i32 0)
78 ; CHECK-NEXT: ret i32 [[TMP0]]
80 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @f(i32 1)
81 ; CHECK-NEXT: ret i32 [[TMP1]]
85 ; Note: folding the most popular case destination into the default
86 ; would prevent switch-to-icmp here.
87 switch i32 %x, label %unreachable [
97 %0 = call i32 @f(i32 0)
100 %1 = call i32 @f(i32 1)
104 ; This would crash because we did not clean up the
105 ; default block of the switch before removing the switch.
107 define void @PR42737(i32* %a, i1 %c) {
108 ; CHECK-LABEL: @PR42737(
110 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[C:%.*]], true
111 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
112 ; CHECK-NEXT: unreachable
115 br i1 %c, label %switch, label %else
122 %cleanup.dest1 = phi i32 [ 0, %else ], [ 3, %entry ]
123 switch i32 %cleanup.dest1, label %unreach1 [
124 i32 0, label %cleanup1
125 i32 3, label %cleanup2
135 %phi2 = phi i32 [ %cleanup.dest1, %switch ]