Jun Bum Lim | 90b6b50 | 2016-12-16 20:38:39 +0000 | [diff] [blame] | 1 | ; RUN: llc -march=avr -print-after=expand-isel-pseudos -cgp-freq-ratio-to-skip-merge=10 < %s 2>&1 | FileCheck %s |
Dylan McKay | 0d4778f | 2016-11-09 23:46:52 +0000 | [diff] [blame] | 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 | ; |
Francis Visoiu Mistrih | da89d18 | 2018-02-08 05:02:00 +0000 | [diff] [blame] | 12 | ; %bb.2.finish: |
Francis Visoiu Mistrih | 39ec2e9 | 2018-02-09 00:10:31 +0000 | [diff] [blame] | 13 | ; successors: %bb.5(?%) %bb.6(?%) |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 14 | ; Predecessors according to CFG: %bb.0 %bb.1 |
Francis Visoiu Mistrih | a8a83d1 | 2017-12-07 10:40:31 +0000 | [diff] [blame] | 15 | ; %0 = PHI %3, <%bb.0>, %5, <%bb.1> |
| 16 | ; %7 = LDIRdK 2 |
| 17 | ; %8 = LDIRdK 1 |
| 18 | ; CPRdRr %2, %0, implicit-def %SREG |
| 19 | ; BREQk <%bb.6>, implicit %SREG |
Dylan McKay | 0d4778f | 2016-11-09 23:46:52 +0000 | [diff] [blame] | 20 | ; |
Francis Visoiu Mistrih | 25528d6 | 2017-12-04 17:18:51 +0000 | [diff] [blame] | 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. |
Dylan McKay | 0d4778f | 2016-11-09 23:46:52 +0000 | [diff] [blame] | 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 | |
Dylan McKay | 820553f | 2018-02-08 09:17:11 +0000 | [diff] [blame] | 52 | ; CHECK: bb.2.finish: |
Francis Visoiu Mistrih | 39ec2e9 | 2018-02-09 00:10:31 +0000 | [diff] [blame] | 53 | ; CHECK: successors: |
Dylan McKay | f7e8ec1 | 2017-12-09 07:51:43 +0000 | [diff] [blame] | 54 | ; CHECK: BREQk [[BRANCHED:%bb.[0-9]+]] |
| 55 | ; CHECK: RJMPk [[DIRECT:%bb.[0-9]+]] |
Dylan McKay | 0d4778f | 2016-11-09 23:46:52 +0000 | [diff] [blame] | 56 | ; CHECK-SAME-DAG: {{.*}}[[BRANCHED]] |
| 57 | ; CHECK-SAME-DAG: {{.*}}[[DIRECT]] |
Dylan McKay | 820553f | 2018-02-08 09:17:11 +0000 | [diff] [blame] | 58 | ; CHECK: bb.3.dead: |