1;; x86 is chosen to show the transform when 8-bit and 16-bit registers are available. 2 3; RUN: opt < %s -codegenprepare -S -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X86 4; RUN: opt < %s -debugify -codegenprepare -S -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=DEBUG 5 6; No change for x86 because 16-bit registers are part of the architecture. 7 8define i32 @widen_switch_i16(i32 %a) { 9entry: 10 %trunc = trunc i32 %a to i16 11 switch i16 %trunc, label %sw.default [ 12 i16 1, label %sw.bb0 13 i16 -1, label %sw.bb1 14 ] 15 16sw.bb0: 17 br label %return 18 19sw.bb1: 20 br label %return 21 22sw.default: 23 br label %return 24 25return: 26 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ] 27 ret i32 %retval 28 29; X86-LABEL: @widen_switch_i16( 30; X86: %trunc = trunc i32 %a to i16 31; X86-NEXT: switch i16 %trunc, label %sw.default [ 32; X86-NEXT: i16 1, label %sw.bb0 33; X86-NEXT: i16 -1, label %sw.bb1 34} 35 36; Widen to 32-bit from a smaller, non-native type. 37 38define i32 @widen_switch_i17(i32 %a) { 39entry: 40 %trunc = trunc i32 %a to i17 41 switch i17 %trunc, label %sw.default [ 42 i17 10, label %sw.bb0 43 i17 -1, label %sw.bb1 44 ] 45 46sw.bb0: 47 br label %return 48 49sw.bb1: 50 br label %return 51 52sw.default: 53 br label %return 54 55return: 56 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ] 57 ret i32 %retval 58 59; X86-LABEL: @widen_switch_i17( 60; X86: %0 = zext i17 %trunc to i32 61; X86-NEXT: switch i32 %0, label %sw.default [ 62; X86-NEXT: i32 10, label %sw.bb0 63; X86-NEXT: i32 131071, label %sw.bb1 64 65; DEBUG-LABEL: @widen_switch_i17( 66; DEBUG: zext i17 %trunc to i32, !dbg [[switch_loc:![0-9]+]] 67; DEBUG-NEXT: switch i32 {{.*}} [ 68; DEBUG-NEXT: label %sw.bb0 69; DEBUG-NEXT: label %sw.bb1 70; DEBUG-NEXT: ], !dbg [[switch_loc]] 71} 72 73; If the switch condition is a sign-extended function argument, then the 74; condition and cases should be sign-extended rather than zero-extended 75; because the sign-extension can be optimized away. 76 77define i32 @widen_switch_i16_sext(i2 signext %a) { 78entry: 79 switch i2 %a, label %sw.default [ 80 i2 1, label %sw.bb0 81 i2 -1, label %sw.bb1 82 ] 83 84sw.bb0: 85 br label %return 86 87sw.bb1: 88 br label %return 89 90sw.default: 91 br label %return 92 93return: 94 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ] 95 ret i32 %retval 96 97; X86-LABEL: @widen_switch_i16_sext( 98; X86: %0 = sext i2 %a to i8 99; X86-NEXT: switch i8 %0, label %sw.default [ 100; X86-NEXT: i8 1, label %sw.bb0 101; X86-NEXT: i8 -1, label %sw.bb1 102} 103 104