1 ;; x86 is chosen to show the transform when 8-bit and 16-bit registers are available.
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
6 ; No change for x86 because 16-bit registers are part of the architecture.
8 define i32 @widen_switch_i16(i32 %a) {
10 %trunc = trunc i32 %a to i16
11 switch i16 %trunc, label %sw.default [
26 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
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
36 ; Widen to 32-bit from a smaller, non-native type.
38 define i32 @widen_switch_i17(i32 %a) {
40 %trunc = trunc i32 %a to i17
41 switch i17 %trunc, label %sw.default [
56 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
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
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]]
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.
77 define i32 @widen_switch_i16_sext(i2 signext %a) {
79 switch i2 %a, label %sw.default [
94 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
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