OLD | NEW |
1 ; This tests the advanced lowering of switch statements. The advanced lowering | 1 ; This tests the advanced lowering of switch statements. The advanced lowering |
2 ; uses jump tables, range tests and binary search. | 2 ; uses jump tables, range tests and binary search. |
3 | 3 |
4 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 | FileCheck %s | 4 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 | FileCheck %s |
5 | 5 |
6 ; Dense but non-continuous ranges should be converted into a jump table. | 6 ; Dense but non-continuous ranges should be converted into a jump table. |
7 define internal i32 @testJumpTable(i32 %a) { | 7 define internal i32 @testJumpTable(i32 %a) { |
8 entry: | 8 entry: |
9 switch i32 %a, label %sw.default [ | 9 switch i32 %a, label %sw.default [ |
10 i32 91, label %sw.default | 10 i32 91, label %sw.default |
(...skipping 14 matching lines...) Expand all Loading... |
25 br label %sw.epilog | 25 br label %sw.epilog |
26 | 26 |
27 sw.epilog: | 27 sw.epilog: |
28 %result.1 = phi i32 [ %add, %sw.default ], [ %tmp, %sw.bb1 ], [ 17, %entry ] | 28 %result.1 = phi i32 [ %add, %sw.default ], [ %tmp, %sw.bb1 ], [ 17, %entry ] |
29 ret i32 %result.1 | 29 ret i32 %result.1 |
30 } | 30 } |
31 ; CHECK-LABEL: testJumpTable | 31 ; CHECK-LABEL: testJumpTable |
32 ; CHECK: sub [[IND:[^,]+]],0x5b | 32 ; CHECK: sub [[IND:[^,]+]],0x5b |
33 ; CHECK-NEXT: cmp [[IND]],0x8 | 33 ; CHECK-NEXT: cmp [[IND]],0x8 |
34 ; CHECK-NEXT: ja | 34 ; CHECK-NEXT: ja |
35 ; CHECK-NEXT: mov [[BASE:[^,]+]],0x0 {{[0-9a-f]+}}: R_386_32 .{{.*}}testJumpTabl
e$jumptable | 35 ; CHECK-NEXT: mov [[TARGET:.*]],DWORD PTR {{\[}}[[IND]]*4+0x0] {{[0-9a-f]+}}: R_
386_32 .{{.*}}testJumpTable$jumptable |
36 ; CHECK-NEXT: mov {{.*}},DWORD PTR {{\[}}[[BASE]]+[[IND]]*4] | 36 ; CHECK-NEXT: jmp [[TARGET]] |
37 ; CHECK-NEXT: jmp | |
38 | 37 |
39 ; Continuous ranges which map to the same target should be grouped and | 38 ; Continuous ranges which map to the same target should be grouped and |
40 ; efficiently tested. | 39 ; efficiently tested. |
41 define internal i32 @testRangeTest() { | 40 define internal i32 @testRangeTest() { |
42 entry: | 41 entry: |
43 switch i32 10, label %sw.default [ | 42 switch i32 10, label %sw.default [ |
44 i32 0, label %sw.epilog | 43 i32 0, label %sw.epilog |
45 i32 1, label %sw.epilog | 44 i32 1, label %sw.epilog |
46 i32 2, label %sw.epilog | 45 i32 2, label %sw.epilog |
47 i32 3, label %sw.epilog | 46 i32 3, label %sw.epilog |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 sw.default: | 209 sw.default: |
211 br label %return | 210 br label %return |
212 | 211 |
213 return: | 212 return: |
214 %retval.0 = phi i32 [ 5, %sw.default ], [ 4, %sw.bb3 ], [ 3, %sw.bb2 ], [ 2, %
sw.bb1 ], [ 1, %entry ] | 213 %retval.0 = phi i32 [ 5, %sw.default ], [ 4, %sw.bb3 ], [ 3, %sw.bb2 ], [ 2, %
sw.bb1 ], [ 1, %entry ] |
215 ret i32 %retval.0 | 214 ret i32 %retval.0 |
216 } | 215 } |
217 | 216 |
218 ; TODO(ascull): this should generate a jump table. For now, just make sure it | 217 ; TODO(ascull): this should generate a jump table. For now, just make sure it |
219 ; doesn't crash the compiler. | 218 ; doesn't crash the compiler. |
OLD | NEW |