1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; Vary legal integer types in data layout. 3; RUN: opt < %s -instcombine -S -default-data-layout=n32 | FileCheck %s --check-prefix=ALL --check-prefix=CHECK32 4; RUN: opt < %s -instcombine -S -default-data-layout=n32:64 | FileCheck %s --check-prefix=ALL --check-prefix=CHECK64 5 6; In all cases, the data-layout is irrelevant. We should shrink as much as possible in InstCombine 7; and allow the backend to expand as much as needed to ensure optimal codegen for any target. 8 9define i32 @positive1(i64 %a) { 10; ALL-LABEL: @positive1( 11; ALL: switch i32 12; ALL-NEXT: i32 10, label %return 13; ALL-NEXT: i32 100, label %sw.bb1 14; ALL-NEXT: i32 1001, label %sw.bb2 15; ALL-NEXT: ] 16; 17entry: 18 %and = and i64 %a, 4294967295 19 switch i64 %and, label %sw.default [ 20 i64 10, label %return 21 i64 100, label %sw.bb1 22 i64 1001, label %sw.bb2 23 ] 24 25sw.bb1: 26 br label %return 27 28sw.bb2: 29 br label %return 30 31sw.default: 32 br label %return 33 34return: 35 %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ] 36 ret i32 %retval.0 37} 38 39define i32 @negative1(i64 %a) { 40; ALL-LABEL: @negative1( 41; ALL: switch i32 42; ALL-NEXT: i32 -10, label %return 43; ALL-NEXT: i32 -100, label %sw.bb1 44; ALL-NEXT: i32 -1001, label %sw.bb2 45; ALL-NEXT: ] 46; 47entry: 48 %or = or i64 %a, -4294967296 49 switch i64 %or, label %sw.default [ 50 i64 -10, label %return 51 i64 -100, label %sw.bb1 52 i64 -1001, label %sw.bb2 53 ] 54 55sw.bb1: 56 br label %return 57 58sw.bb2: 59 br label %return 60 61sw.default: 62 br label %return 63 64return: 65 %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ] 66 ret i32 %retval.0 67} 68 69; Make sure truncating a constant int larger than 64-bit doesn't trigger an 70; assertion. 71 72define i32 @trunc72to68(i72 %a) { 73; ALL-LABEL: @trunc72to68( 74; ALL: switch i68 75; ALL-NEXT: i68 10, label %return 76; ALL-NEXT: i68 100, label %sw.bb1 77; ALL-NEXT: i68 1001, label %sw.bb2 78; ALL-NEXT: ] 79; 80entry: 81 %and = and i72 %a, 295147905179352825855 82 switch i72 %and, label %sw.default [ 83 i72 10, label %return 84 i72 100, label %sw.bb1 85 i72 1001, label %sw.bb2 86 ] 87 88sw.bb1: 89 br label %return 90 91sw.bb2: 92 br label %return 93 94sw.default: 95 br label %return 96 97return: 98 %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ] 99 ret i32 %retval.0 100} 101 102; Make sure to avoid assertion crashes and use the type before 103; truncation to generate the sub constant expressions that leads 104; to the recomputed condition. 105 106define void @trunc64to59(i64 %a) { 107; ALL-LABEL: @trunc64to59( 108; ALL: switch i59 109; ALL-NEXT: i59 0, label %sw.bb1 110; ALL-NEXT: i59 18717182647723699, label %sw.bb2 111; ALL-NEXT: ] 112; 113entry: 114 %tmp0 = and i64 %a, 15 115 %tmp1 = mul i64 %tmp0, -6425668444178048401 116 %tmp2 = add i64 %tmp1, 5170979678563097242 117 %tmp3 = mul i64 %tmp2, 1627972535142754813 118 switch i64 %tmp3, label %sw.default [ 119 i64 847514119312061490, label %sw.bb1 120 i64 866231301959785189, label %sw.bb2 121 ] 122 123sw.bb1: 124 br label %sw.default 125 126sw.bb2: 127 br label %sw.default 128 129sw.default: 130 ret void 131} 132