Dylan McKay | 0d4778f | 2016-11-09 23:46:52 +0000 | [diff] [blame^] | 1 | ; RUN: llc -march=avr -print-after=expand-isel-pseudos < %s 2>&1 | FileCheck %s |
| 2 | |
| 3 | ; Because `switch` seems to trigger Machine Basic Blocks to be ordered |
| 4 | ; in a different order than they were constructed, this exposes an |
| 5 | ; error in the `expand-isel-pseudos` pass. Specifically, it thought we |
| 6 | ; could always fallthrough to a newly-constructed MBB. However, |
| 7 | ; there's no guarantee that either of the constructed MBBs need to |
| 8 | ; occur immediately after the currently-focused one! |
| 9 | ; |
| 10 | ; This issue manifests in a CFG that looks something like this: |
| 11 | ; |
| 12 | ; BB#2: derived from LLVM BB %finish |
| 13 | ; Predecessors according to CFG: BB#0 BB#1 |
| 14 | ; %vreg0<def> = PHI %vreg3, <BB#0>, %vreg5, <BB#1> |
| 15 | ; %vreg7<def> = LDIRdK 2 |
| 16 | ; %vreg8<def> = LDIRdK 1 |
| 17 | ; CPRdRr %vreg2, %vreg0, %SREG<imp-def> |
| 18 | ; BREQk <BB#6>, %SREG<imp-use> |
| 19 | ; Successors according to CFG: BB#5(?%) BB#6(?%) |
| 20 | ; |
| 21 | ; The code assumes it the fallthrough block after this is BB#5, but |
| 22 | ; it's actually BB#3! To be proper, there should be an unconditional |
| 23 | ; jump tying this block to BB#5. |
| 24 | |
| 25 | define i8 @select_must_add_unconditional_jump(i8 %arg0, i8 %arg1) unnamed_addr { |
| 26 | entry-block: |
| 27 | switch i8 %arg0, label %dead [ |
| 28 | i8 0, label %zero |
| 29 | i8 1, label %one |
| 30 | ] |
| 31 | |
| 32 | zero: |
| 33 | br label %finish |
| 34 | |
| 35 | one: |
| 36 | br label %finish |
| 37 | |
| 38 | finish: |
| 39 | %predicate = phi i8 [ 50, %zero ], [ 100, %one ] |
| 40 | %is_eq = icmp eq i8 %arg1, %predicate |
| 41 | %result = select i1 %is_eq, i8 1, i8 2 |
| 42 | ret i8 %result |
| 43 | |
| 44 | dead: |
| 45 | ret i8 0 |
| 46 | } |
| 47 | |
| 48 | ; This check may be a bit brittle, but the important thing is that the |
| 49 | ; basic block containing `select` needs to contain explicit jumps to |
| 50 | ; both successors. |
| 51 | |
| 52 | ; CHECK: BB#2: derived from LLVM BB %finish |
| 53 | ; CHECK: BREQk <[[BRANCHED:BB#[0-9]+]]> |
| 54 | ; CHECK: RJMPk <[[DIRECT:BB#[0-9]+]]> |
| 55 | ; CHECK: Successors according to CFG |
| 56 | ; CHECK-SAME-DAG: {{.*}}[[BRANCHED]] |
| 57 | ; CHECK-SAME-DAG: {{.*}}[[DIRECT]] |
| 58 | ; CHECK: BB#3: derived from LLVM BB |