Joerg Sonnenberger | fa73674 | 2017-03-26 06:44:08 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -latesimplifycfg -S | FileCheck %s |
James Molloy | b2e436d | 2016-08-01 07:45:11 +0000 | [diff] [blame] | 2 | |
| 3 | target datalayout = "e-n32" |
| 4 | |
| 5 | ; CHECK-LABEL: @test1 |
Benjamin Kramer | 000a87d | 2016-08-05 14:58:34 +0000 | [diff] [blame] | 6 | ; CHECK: %[[SUB:.*]] = sub i32 %a, 97 |
| 7 | ; CHECK: %[[LSHR:.*]] = lshr i32 %[[SUB]], 2 |
| 8 | ; CHECK: %[[SHL:.*]] = shl i32 %[[SUB]], 30 |
| 9 | ; CHECK: %[[OR:.*]] = or i32 %[[LSHR]], %[[SHL]] |
| 10 | ; CHECK: switch i32 %[[OR]], label %def [ |
James Molloy | b2e436d | 2016-08-01 07:45:11 +0000 | [diff] [blame] | 11 | ; CHECK: i32 0, label %one |
| 12 | ; CHECK: i32 1, label %two |
| 13 | ; CHECK: i32 2, label %three |
| 14 | ; CHECK: ] |
| 15 | define i32 @test1(i32 %a) { |
| 16 | switch i32 %a, label %def [ |
| 17 | i32 97, label %one |
| 18 | i32 101, label %two |
| 19 | i32 105, label %three |
| 20 | i32 109, label %three |
| 21 | ] |
| 22 | |
| 23 | def: |
| 24 | ret i32 8867 |
| 25 | |
| 26 | one: |
| 27 | ret i32 11984 |
| 28 | two: |
| 29 | ret i32 1143 |
| 30 | three: |
| 31 | ret i32 99783 |
| 32 | } |
| 33 | |
| 34 | ; Optimization shouldn't trigger; bitwidth > 64 |
| 35 | ; CHECK-LABEL: @test2 |
| 36 | ; CHECK: switch i128 %a, label %def |
| 37 | define i128 @test2(i128 %a) { |
| 38 | switch i128 %a, label %def [ |
| 39 | i128 97, label %one |
| 40 | i128 101, label %two |
| 41 | i128 105, label %three |
| 42 | i128 109, label %three |
| 43 | ] |
| 44 | |
| 45 | def: |
| 46 | ret i128 8867 |
| 47 | |
| 48 | one: |
| 49 | ret i128 11984 |
| 50 | two: |
| 51 | ret i128 1143 |
| 52 | three: |
| 53 | ret i128 99783 |
| 54 | } |
| 55 | |
| 56 | |
| 57 | ; Optimization shouldn't trigger; no holes present |
| 58 | ; CHECK-LABEL: @test3 |
| 59 | ; CHECK: switch i32 %a, label %def |
| 60 | define i32 @test3(i32 %a) { |
| 61 | switch i32 %a, label %def [ |
| 62 | i32 97, label %one |
| 63 | i32 98, label %two |
| 64 | i32 99, label %three |
| 65 | ] |
| 66 | |
| 67 | def: |
| 68 | ret i32 8867 |
| 69 | |
| 70 | one: |
| 71 | ret i32 11984 |
| 72 | two: |
| 73 | ret i32 1143 |
| 74 | three: |
| 75 | ret i32 99783 |
| 76 | } |
| 77 | |
| 78 | ; Optimization shouldn't trigger; not an arithmetic progression |
| 79 | ; CHECK-LABEL: @test4 |
| 80 | ; CHECK: switch i32 %a, label %def |
| 81 | define i32 @test4(i32 %a) { |
| 82 | switch i32 %a, label %def [ |
| 83 | i32 97, label %one |
| 84 | i32 102, label %two |
| 85 | i32 105, label %three |
| 86 | i32 109, label %three |
| 87 | ] |
| 88 | |
| 89 | def: |
| 90 | ret i32 8867 |
| 91 | |
| 92 | one: |
| 93 | ret i32 11984 |
| 94 | two: |
| 95 | ret i32 1143 |
| 96 | three: |
| 97 | ret i32 99783 |
| 98 | } |
| 99 | |
| 100 | ; Optimization shouldn't trigger; not a power of two |
| 101 | ; CHECK-LABEL: @test5 |
| 102 | ; CHECK: switch i32 %a, label %def |
| 103 | define i32 @test5(i32 %a) { |
| 104 | switch i32 %a, label %def [ |
| 105 | i32 97, label %one |
| 106 | i32 102, label %two |
| 107 | i32 107, label %three |
| 108 | i32 112, label %three |
| 109 | ] |
| 110 | |
| 111 | def: |
| 112 | ret i32 8867 |
| 113 | |
| 114 | one: |
| 115 | ret i32 11984 |
| 116 | two: |
| 117 | ret i32 1143 |
| 118 | three: |
| 119 | ret i32 99783 |
| 120 | } |
| 121 | |
| 122 | ; CHECK-LABEL: @test6 |
Benjamin Kramer | 000a87d | 2016-08-05 14:58:34 +0000 | [diff] [blame] | 123 | ; CHECK: %[[SUB:.*]] = sub i32 %a, -109 |
| 124 | ; CHECK: %[[LSHR:.*]] = lshr i32 %[[SUB]], 2 |
| 125 | ; CHECK: %[[SHL:.*]] = shl i32 %[[SUB]], 30 |
| 126 | ; CHECK: %[[OR:.*]] = or i32 %[[LSHR]], %[[SHL]] |
| 127 | ; CHECK: switch i32 %[[OR]], label %def [ |
James Molloy | b2e436d | 2016-08-01 07:45:11 +0000 | [diff] [blame] | 128 | define i32 @test6(i32 %a) optsize { |
| 129 | switch i32 %a, label %def [ |
| 130 | i32 -97, label %one |
| 131 | i32 -101, label %two |
| 132 | i32 -105, label %three |
| 133 | i32 -109, label %three |
| 134 | ] |
| 135 | |
| 136 | def: |
| 137 | ret i32 8867 |
| 138 | |
| 139 | one: |
| 140 | ret i32 11984 |
| 141 | two: |
| 142 | ret i32 1143 |
| 143 | three: |
| 144 | ret i32 99783 |
| 145 | } |
| 146 | |
| 147 | ; CHECK-LABEL: @test7 |
Benjamin Kramer | 000a87d | 2016-08-05 14:58:34 +0000 | [diff] [blame] | 148 | ; CHECK: %[[SUB:.*]] = sub i8 %a, -36 |
| 149 | ; CHECK: %[[LSHR:.*]] = lshr i8 %[[SUB]], 2 |
| 150 | ; CHECK: %[[SHL:.*]] = shl i8 %[[SUB]], 6 |
| 151 | ; CHECK: %[[OR:.*]] = or i8 %[[LSHR]], %[[SHL]] |
| 152 | ; CHECK: switch.tableidx = {{.*}} %[[OR]] |
James Molloy | b2e436d | 2016-08-01 07:45:11 +0000 | [diff] [blame] | 153 | define i8 @test7(i8 %a) optsize { |
| 154 | switch i8 %a, label %def [ |
| 155 | i8 220, label %one |
| 156 | i8 224, label %two |
| 157 | i8 228, label %three |
| 158 | i8 232, label %three |
| 159 | ] |
| 160 | |
| 161 | def: |
| 162 | ret i8 8867 |
| 163 | |
| 164 | one: |
| 165 | ret i8 11984 |
| 166 | two: |
| 167 | ret i8 1143 |
| 168 | three: |
| 169 | ret i8 99783 |
| 170 | } |
| 171 | |
| 172 | ; CHECK-LABEL: @test8 |
Benjamin Kramer | 000a87d | 2016-08-05 14:58:34 +0000 | [diff] [blame] | 173 | ; CHECK: %[[SUB:.*]] = sub i32 %a, 97 |
| 174 | ; CHECK: %[[LSHR:.*]] = lshr i32 %1, 2 |
| 175 | ; CHECK: %[[SHL:.*]] = shl i32 %1, 30 |
| 176 | ; CHECK: %[[OR:.*]] = or i32 %[[LSHR]], %[[SHL]] |
| 177 | ; CHECK: switch i32 %[[OR]], label %def [ |
James Molloy | b2e436d | 2016-08-01 07:45:11 +0000 | [diff] [blame] | 178 | define i32 @test8(i32 %a) optsize { |
| 179 | switch i32 %a, label %def [ |
| 180 | i32 97, label %one |
| 181 | i32 101, label %two |
| 182 | i32 105, label %three |
| 183 | i32 113, label %three |
| 184 | ] |
| 185 | |
| 186 | def: |
| 187 | ret i32 8867 |
| 188 | |
| 189 | one: |
| 190 | ret i32 11984 |
| 191 | two: |
| 192 | ret i32 1143 |
| 193 | three: |
| 194 | ret i32 99783 |
James Molloy | bade86c | 2016-08-01 09:34:48 +0000 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | ; CHECK-LABEL: @test9 |
| 198 | ; CHECK: switch |
| 199 | ; CHECK: i32 6 |
| 200 | ; CHECK: i32 7 |
| 201 | ; CHECK: i32 0 |
| 202 | ; CHECK: i32 2 |
| 203 | define i32 @test9(i32 %a) { |
| 204 | switch i32 %a, label %def [ |
| 205 | i32 18, label %one |
| 206 | i32 20, label %two |
| 207 | i32 6, label %three |
| 208 | i32 10, label %three |
| 209 | ] |
| 210 | |
| 211 | def: |
| 212 | ret i32 8867 |
| 213 | |
| 214 | one: |
| 215 | ret i32 11984 |
| 216 | two: |
| 217 | ret i32 1143 |
| 218 | three: |
| 219 | ret i32 99783 |
| 220 | } |
| 221 | |