1 ; RUN: opt %s -simplifycfg -S | FileCheck %s 2 3 declare i32 @f(i32) 4 5 define i32 @basic(i32 %x) { 6 ; CHECK-LABEL: @basic 7 ; CHECK: x.off = add i32 %x, -5 8 ; CHECK: %switch = icmp ult i32 %x.off, 3 9 ; CHECK: br i1 %switch, label %a, label %default 10 11 entry: 12 switch i32 %x, label %default [ 13 i32 5, label %a 14 i32 6, label %a 15 i32 7, label %a 16 ] 17 default: 18 %0 = call i32 @f(i32 0) 19 ret i32 %0 20 a: 21 %1 = call i32 @f(i32 1) 22 ret i32 %1 23 } 24 25 26 define i32 @unreachable(i32 %x) { 27 ; CHECK-LABEL: @unreachable 28 ; CHECK: x.off = add i32 %x, -5 29 ; CHECK: %switch = icmp ult i32 %x.off, 3 30 ; CHECK: br i1 %switch, label %a, label %b 31 32 entry: 33 switch i32 %x, label %unreachable [ 34 i32 5, label %a 35 i32 6, label %a 36 i32 7, label %a 37 i32 10, label %b 38 i32 20, label %b 39 i32 30, label %b 40 i32 40, label %b 41 ] 42 unreachable: 43 unreachable 44 a: 45 %0 = call i32 @f(i32 0) 46 ret i32 %0 47 b: 48 %1 = call i32 @f(i32 1) 49 ret i32 %1 50 } 51 52 53 define i32 @unreachable2(i32 %x) { 54 ; CHECK-LABEL: @unreachable2 55 ; CHECK: x.off = add i32 %x, -5 56 ; CHECK: %switch = icmp ult i32 %x.off, 3 57 ; CHECK: br i1 %switch, label %a, label %b 58 59 entry: 60 ; Note: folding the most popular case destination into the default 61 ; would prevent switch-to-icmp here. 62 switch i32 %x, label %unreachable [ 63 i32 5, label %a 64 i32 6, label %a 65 i32 7, label %a 66 i32 10, label %b 67 i32 20, label %b 68 ] 69 unreachable: 70 unreachable 71 a: 72 %0 = call i32 @f(i32 0) 73 ret i32 %0 74 b: 75 %1 = call i32 @f(i32 1) 76 ret i32 %1 77 } 78