|
| 1 | +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py |
| 2 | +# RUN: llc -mtriple=thumbv7-apple-ios -run-pass=if-converter %s -o - | FileCheck %s |
| 3 | + |
| 4 | +# Testcase with unanalyzable branches (that may fallthrough) in the BB |
| 5 | +# following the diamond/triangle. |
| 6 | + |
| 7 | +# Goal here is to showcase a problem seen in the IfConverter when |
| 8 | +# AnalyzeBranch is indicating that the branches couldn't be analyzed. Problem |
| 9 | +# was originally seen for an out-of-tree target, and here we use ARM and a |
| 10 | +# MBB with two conditional jumps to make AnalyzeBranch return false. |
| 11 | +# |
| 12 | +# The problem was that if-converter when analyzing branches was using a |
| 13 | +# variable named HasFallThrough, to remember that an MBB could fallthrough to |
| 14 | +# the textual successor. When HasFallThrough is set we know that there are |
| 15 | +# fallthrough exits, but the opposite is not guaranteed. If |
| 16 | +# HasFallThrough==false there could still be fallthrough exists in situations |
| 17 | +# when analyzeBranch found unanalyzable branches. There were however a couple |
| 18 | +# of places in the code that checked !HasFallThrough assuming that it would |
| 19 | +# imply that there was no fallthrough exit. |
| 20 | +# |
| 21 | +# As a consequence we could end up merging blocks at the end of a converted |
| 22 | +# diamond/triangle and while doing that we messed up when fixing up the CFG |
| 23 | +# related to fallthrough edges. For the test cases below we incorrectly ended |
| 24 | +# up ended up with a fallthrough from the MBBs with two Bcc instructions to |
| 25 | +# the MBB with the STRH after if conversion. |
| 26 | +# |
| 27 | +--- |
| 28 | +name: avoidMergeBlockDiamond |
| 29 | +body: | |
| 30 | + ; CHECK-LABEL: name: avoidMergeBlockDiamond |
| 31 | + ; CHECK: bb.0: |
| 32 | + ; CHECK-NEXT: successors: %bb.2(0x80000000) |
| 33 | + ; CHECK-NEXT: {{ $}} |
| 34 | + ; CHECK-NEXT: $sp = tADDspi $sp, 2, 1 /* CC::ne */, $cpsr |
| 35 | + ; CHECK-NEXT: $sp = tADDspi $sp, 1, 0 /* CC::eq */, $cpsr, implicit $sp |
| 36 | + ; CHECK-NEXT: $sp = tADDspi $sp, 3, 14 /* CC::al */, $noreg |
| 37 | + ; CHECK-NEXT: tBcc %bb.2, 1 /* CC::ne */, $cpsr |
| 38 | + ; CHECK-NEXT: tBcc %bb.2, 1 /* CC::ne */, $cpsr |
| 39 | + ; CHECK-NEXT: {{ $}} |
| 40 | + ; CHECK-NEXT: bb.1: |
| 41 | + ; CHECK-NEXT: successors: %bb.1(0x80000000) |
| 42 | + ; CHECK-NEXT: {{ $}} |
| 43 | + ; CHECK-NEXT: STRH $sp, $sp, $noreg, 0, 14 /* CC::al */, $noreg |
| 44 | + ; CHECK-NEXT: tB %bb.1, 14 /* CC::al */, $noreg |
| 45 | + ; CHECK-NEXT: {{ $}} |
| 46 | + ; CHECK-NEXT: bb.2: |
| 47 | + ; CHECK-NEXT: tBX_RET 14 /* CC::al */, $noreg |
| 48 | + bb.0: |
| 49 | + tBcc %bb.2, 1, $cpsr |
| 50 | +
|
| 51 | + bb.1: |
| 52 | + $sp = tADDspi $sp, 1, 14, _ |
| 53 | + tB %bb.4, 14, $noreg |
| 54 | +
|
| 55 | + bb.2: |
| 56 | + $sp = tADDspi $sp, 2, 14, _ |
| 57 | + tB %bb.4, 14, $noreg |
| 58 | +
|
| 59 | + bb.3: |
| 60 | + STRH $sp, $sp, $noreg, 0, 14, $noreg |
| 61 | + tB %bb.3, 14, $noreg |
| 62 | +
|
| 63 | + bb.4: |
| 64 | + $sp = tADDspi $sp, 3, 14, _ |
| 65 | + tBcc %bb.5, 1, $cpsr |
| 66 | + tBcc %bb.5, 1, $cpsr |
| 67 | +
|
| 68 | + bb.5: |
| 69 | + successors: |
| 70 | + tBX_RET 14, _ |
| 71 | +... |
| 72 | + |
| 73 | +# Similar to the above, but with a triangle. |
| 74 | +--- |
| 75 | +name: avoidMergeBlockTriangle |
| 76 | +body: | |
| 77 | + ; CHECK-LABEL: name: avoidMergeBlockTriangle |
| 78 | + ; CHECK: bb.0: |
| 79 | + ; CHECK-NEXT: successors: %bb.2(0x80000000) |
| 80 | + ; CHECK-NEXT: {{ $}} |
| 81 | + ; CHECK-NEXT: $sp = tADDspi $sp, 1, 1 /* CC::ne */, $cpsr |
| 82 | + ; CHECK-NEXT: $sp = tADDspi $sp, 2, 14 /* CC::al */, $noreg |
| 83 | + ; CHECK-NEXT: tBcc %bb.2, 1 /* CC::ne */, $cpsr |
| 84 | + ; CHECK-NEXT: tBcc %bb.2, 1 /* CC::ne */, $cpsr |
| 85 | + ; CHECK-NEXT: {{ $}} |
| 86 | + ; CHECK-NEXT: bb.1: |
| 87 | + ; CHECK-NEXT: successors: %bb.1(0x80000000) |
| 88 | + ; CHECK-NEXT: {{ $}} |
| 89 | + ; CHECK-NEXT: STRH $sp, $sp, $noreg, 0, 14 /* CC::al */, $noreg |
| 90 | + ; CHECK-NEXT: tB %bb.1, 14 /* CC::al */, $noreg |
| 91 | + ; CHECK-NEXT: {{ $}} |
| 92 | + ; CHECK-NEXT: bb.2: |
| 93 | + ; CHECK-NEXT: tBX_RET 14 /* CC::al */, $noreg |
| 94 | + bb.0: |
| 95 | + tBcc %bb.1, 1, $cpsr |
| 96 | + tB %bb.3, 14, $noreg |
| 97 | +
|
| 98 | + bb.1: |
| 99 | + $sp = tADDspi $sp, 1, 14, _ |
| 100 | + tB %bb.3, 14, $noreg |
| 101 | +
|
| 102 | + bb.2: |
| 103 | + STRH $sp, $sp, $noreg, 0, 14, $noreg |
| 104 | + tB %bb.2, 14, $noreg |
| 105 | +
|
| 106 | + bb.3: |
| 107 | + $sp = tADDspi $sp, 2, 14, _ |
| 108 | + tBcc %bb.4, 1, $cpsr |
| 109 | + tBcc %bb.4, 1, $cpsr |
| 110 | +
|
| 111 | + bb.4: |
| 112 | + successors: |
| 113 | + tBX_RET 14, _ |
| 114 | +... |
0 commit comments