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 ; X86 prefers i32 over i16 for address calculation.
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: %0 = zext i16 %trunc to i32
32 ; X86-NEXT: switch i32 %0, label %sw.default [
33 ; X86-NEXT: i32 1, label %sw.bb0
34 ; X86-NEXT: i32 65535, label %sw.bb1
37 ; Widen to 32-bit from a smaller, non-native type.
39 define i32 @widen_switch_i17(i32 %a) {
41 %trunc = trunc i32 %a to i17
42 switch i17 %trunc, label %sw.default [
57 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
60 ; X86-LABEL: @widen_switch_i17(
61 ; X86: %0 = zext i17 %trunc to i32
62 ; X86-NEXT: switch i32 %0, label %sw.default [
63 ; X86-NEXT: i32 10, label %sw.bb0
64 ; X86-NEXT: i32 131071, label %sw.bb1
66 ; DEBUG-LABEL: @widen_switch_i17(
67 ; DEBUG: zext i17 %trunc to i32, !dbg [[switch_loc:![0-9]+]]
68 ; DEBUG-NEXT: switch i32 {{.*}} [
69 ; DEBUG-NEXT: label %sw.bb0
70 ; DEBUG-NEXT: label %sw.bb1
71 ; DEBUG-NEXT: ], !dbg [[switch_loc]]
74 ; If the switch condition is a sign-extended function argument, then the
75 ; condition and cases should be sign-extended rather than zero-extended
76 ; because the sign-extension can be optimized away.
78 define i32 @widen_switch_i16_sext(i2 signext %a) {
80 switch i2 %a, label %sw.default [
95 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
98 ; X86-LABEL: @widen_switch_i16_sext(
99 ; X86: %0 = sext i2 %a to i32
100 ; X86-NEXT: switch i32 %0, label %sw.default [
101 ; X86-NEXT: i32 1, label %sw.bb0
102 ; X86-NEXT: i32 -1, label %sw.bb1