105 lines · plain
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=X864; RUN: opt < %s -debugify -codegenprepare -S -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=DEBUG5 6; X86 prefers i32 over i16 for address calculation.7 8define i32 @widen_switch_i16(i32 %a) {9entry:10 %trunc = trunc i32 %a to i1611 switch i16 %trunc, label %sw.default [12 i16 1, label %sw.bb013 i16 -1, label %sw.bb114 ]15 16sw.bb0:17 br label %return18 19sw.bb1:20 br label %return21 22sw.default:23 br label %return24 25return:26 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]27 ret i32 %retval28 29; X86-LABEL: @widen_switch_i16(30; X86: %trunc = trunc i32 %a to i1631; X86-NEXT: %0 = zext i16 %trunc to i3232; X86-NEXT: switch i32 %0, label %sw.default [33; X86-NEXT: i32 1, label %sw.bb034; X86-NEXT: i32 65535, label %sw.bb135}36 37; Widen to 32-bit from a smaller, non-native type.38 39define i32 @widen_switch_i17(i32 %a) {40entry:41 %trunc = trunc i32 %a to i1742 switch i17 %trunc, label %sw.default [43 i17 10, label %sw.bb044 i17 -1, label %sw.bb145 ]46 47sw.bb0:48 br label %return49 50sw.bb1:51 br label %return52 53sw.default:54 br label %return55 56return:57 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]58 ret i32 %retval59 60; X86-LABEL: @widen_switch_i17(61; X86: %0 = zext i17 %trunc to i3262; X86-NEXT: switch i32 %0, label %sw.default [63; X86-NEXT: i32 10, label %sw.bb064; X86-NEXT: i32 131071, label %sw.bb165 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.bb070; DEBUG-NEXT: label %sw.bb171; DEBUG-NEXT: ], !dbg [[switch_loc]]72}73 74; If the switch condition is a sign-extended function argument, then the75; condition and cases should be sign-extended rather than zero-extended76; because the sign-extension can be optimized away.77 78define i32 @widen_switch_i16_sext(i2 signext %a) {79entry:80 switch i2 %a, label %sw.default [81 i2 1, label %sw.bb082 i2 -1, label %sw.bb183 ]84 85sw.bb0:86 br label %return87 88sw.bb1:89 br label %return90 91sw.default:92 br label %return93 94return:95 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]96 ret i32 %retval97 98; X86-LABEL: @widen_switch_i16_sext(99; X86: %0 = sext i2 %a to i32100; X86-NEXT: switch i32 %0, label %sw.default [101; X86-NEXT: i32 1, label %sw.bb0102; X86-NEXT: i32 -1, label %sw.bb1103}104 105