1 ;; PowerPC is arbitralily chosen as a 32/64-bit RISC representative to show the transform in all tests.
2 ;; x86 is chosen to show that the transform may differ when 8-bit and 16-bit registers are available.
4 ; RUN: opt < %s -codegenprepare -S -mtriple=powerpc64-unknown-unknown | FileCheck %s --check-prefix=PPC --check-prefix=ALL
5 ; RUN: opt < %s -codegenprepare -S -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X86 --check-prefix=ALL
7 ; PPC widens to 32-bit; no change for x86 because 16-bit registers are part of the architecture.
9 define i32 @widen_switch_i16(i32 %a) {
11 %trunc = trunc i32 %a to i16
12 switch i16 %trunc, label %sw.default [
27 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
30 ; ALL-LABEL: @widen_switch_i16(
31 ; PPC: %0 = zext i16 %trunc to i32
32 ; PPC-NEXT: switch i32 %0, label %sw.default [
33 ; PPC-NEXT: i32 1, label %return
34 ; PPC-NEXT: i32 65535, label %sw.bb1
36 ; X86: %trunc = trunc i32 %a to i16
37 ; X86-NEXT: switch i16 %trunc, label %sw.default [
38 ; X86-NEXT: i16 1, label %return
39 ; X86-NEXT: i16 -1, label %sw.bb1
42 ; Both architectures widen to 32-bit from a smaller, non-native type.
44 define i32 @widen_switch_i17(i32 %a) {
46 %trunc = trunc i32 %a to i17
47 switch i17 %trunc, label %sw.default [
62 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
65 ; ALL-LABEL: @widen_switch_i17(
66 ; ALL: %0 = zext i17 %trunc to i32
67 ; ALL-NEXT: switch i32 %0, label %sw.default [
68 ; ALL-NEXT: i32 10, label %return
69 ; ALL-NEXT: i32 131071, label %sw.bb1
72 ; If the switch condition is a sign-extended function argument, then the
73 ; condition and cases should be sign-extended rather than zero-extended
74 ; because the sign-extension can be optimized away.
76 define i32 @widen_switch_i16_sext(i2 signext %a) {
78 switch i2 %a, label %sw.default [
93 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
96 ; ALL-LABEL: @widen_switch_i16_sext(
97 ; PPC: %0 = sext i2 %a to i32
98 ; PPC-NEXT: switch i32 %0, label %sw.default [
99 ; PPC-NEXT: i32 1, label %return
100 ; PPC-NEXT: i32 -1, label %sw.bb1
102 ; X86: %0 = sext i2 %a to i8
103 ; X86-NEXT: switch i8 %0, label %sw.default [
104 ; X86-NEXT: i8 1, label %return
105 ; X86-NEXT: i8 -1, label %sw.bb1