| 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: %if --need=allow_dump --command %p2i -i %s --filetype=asm --assemble \ | 4 ; RUN: %p2i -i %s --filetype=obj --disassemble --args -O2 | FileCheck %s |
| 5 ; RUN: --disassemble --args --adv-switch -O2 | FileCheck %s | |
| 6 | 5 |
| 7 ; 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. |
| 8 define internal i32 @testJumpTable(i32 %a) { | 7 define internal i32 @testJumpTable(i32 %a) { |
| 9 entry: | 8 entry: |
| 10 switch i32 %a, label %sw.default [ | 9 switch i32 %a, label %sw.default [ |
| 11 i32 91, label %sw.default | 10 i32 91, label %sw.default |
| 12 i32 92, label %sw.bb1 | 11 i32 92, label %sw.bb1 |
| 13 i32 93, label %sw.default | 12 i32 93, label %sw.default |
| 14 i32 99, label %sw.bb1 | 13 i32 99, label %sw.bb1 |
| 15 i32 98, label %sw.default | 14 i32 98, label %sw.default |
| (...skipping 10 matching lines...) Expand all Loading... |
| 26 br label %sw.epilog | 25 br label %sw.epilog |
| 27 | 26 |
| 28 sw.epilog: | 27 sw.epilog: |
| 29 %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 ] |
| 30 ret i32 %result.1 | 29 ret i32 %result.1 |
| 31 } | 30 } |
| 32 ; CHECK-LABEL: testJumpTable | 31 ; CHECK-LABEL: testJumpTable |
| 33 ; CHECK: sub [[IND:[^,]+]],0x5b | 32 ; CHECK: sub [[IND:[^,]+]],0x5b |
| 34 ; CHECK-NEXT: cmp [[IND]],0x8 | 33 ; CHECK-NEXT: cmp [[IND]],0x8 |
| 35 ; CHECK-NEXT: ja | 34 ; CHECK-NEXT: ja |
| 36 ; CHECK-NEXT: mov [[BASE:[^,]+]],0x0 {{[0-9a-f]+}}: R_386_32 .rodata.testJumpTab
le$jumptable | 35 ; CHECK-NEXT: mov [[BASE:[^,]+]],0x0 {{[0-9a-f]+}}: R_386_32 .{{.*}}testJumpTabl
e$jumptable |
| 37 ; CHECK-NEXT: mov {{.*}},DWORD PTR {{\[}}[[BASE]]+[[IND]]*4] | 36 ; CHECK-NEXT: mov {{.*}},DWORD PTR {{\[}}[[BASE]]+[[IND]]*4] |
| 38 ; CHECK-NEXT: jmp | 37 ; CHECK-NEXT: jmp |
| 39 | 38 |
| 40 ; Continuous ranges which map to the same target should be grouped and | 39 ; Continuous ranges which map to the same target should be grouped and |
| 41 ; efficiently tested. | 40 ; efficiently tested. |
| 42 define internal i32 @testRangeTest() { | 41 define internal i32 @testRangeTest() { |
| 43 entry: | 42 entry: |
| 44 switch i32 10, label %sw.default [ | 43 switch i32 10, label %sw.default [ |
| 45 i32 0, label %sw.epilog | 44 i32 0, label %sw.epilog |
| 46 i32 1, label %sw.epilog | 45 i32 1, label %sw.epilog |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 sw.default: | 210 sw.default: |
| 212 br label %return | 211 br label %return |
| 213 | 212 |
| 214 return: | 213 return: |
| 215 %retval.0 = phi i32 [ 5, %sw.default ], [ 4, %sw.bb3 ], [ 3, %sw.bb2 ], [ 2, %
sw.bb1 ], [ 1, %entry ] | 214 %retval.0 = phi i32 [ 5, %sw.default ], [ 4, %sw.bb3 ], [ 3, %sw.bb2 ], [ 2, %
sw.bb1 ], [ 1, %entry ] |
| 216 ret i32 %retval.0 | 215 ret i32 %retval.0 |
| 217 } | 216 } |
| 218 | 217 |
| 219 ; TODO(ascull): this should generate a jump table. For now, just make sure it | 218 ; TODO(ascull): this should generate a jump table. For now, just make sure it |
| 220 ; doesn't crash the compiler. | 219 ; doesn't crash the compiler. |
| OLD | NEW |