115 lines · plain
1# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py2# RUN: llc -mtriple=thumbv7-apple-ios -run-pass=if-converter %s -o - | FileCheck %s3 4# Testcase with unanalyzable branches (that may fallthrough) in the BB5# following the diamond/triangle.6 7# Goal here is to showcase a problem seen in the IfConverter when8# AnalyzeBranch is indicating that the branches couldn't be analyzed. Problem9# was originally seen for an out-of-tree target, and here we use ARM and a10# MBB with two conditional jumps to make AnalyzeBranch return false.11#12# The problem was that if-converter when analyzing branches was using a13# variable named HasFallThrough, to remember that an MBB could fallthrough to14# the textual successor. When HasFallThrough is set we know that there are15# fallthrough exits, but the opposite is not guaranteed. If16# HasFallThrough==false there could still be fallthrough exists in situations17# when analyzeBranch found unanalyzable branches. There were however a couple18# of places in the code that checked !HasFallThrough assuming that it would19# imply that there was no fallthrough exit.20#21# As a consequence we could end up merging blocks at the end of a converted22# diamond/triangle and while doing that we messed up when fixing up the CFG23# related to fallthrough edges. For the test cases below we incorrectly ended24# up with a fallthrough from the MBBs with two Bcc instructions to the MBB25# with the STRH after if conversion.26#27---28name: avoidMergeBlockDiamond29body: |30 ; CHECK-LABEL: name: avoidMergeBlockDiamond31 ; CHECK: bb.0:32 ; CHECK-NEXT: successors: %bb.1(0x80000000)33 ; CHECK-NEXT: {{ $}}34 ; CHECK-NEXT: $sp = tADDspi $sp, 2, 1 /* CC::ne */, $cpsr35 ; CHECK-NEXT: $sp = tADDspi $sp, 1, 0 /* CC::eq */, $cpsr, implicit $sp36 ; CHECK-NEXT: $sp = tADDspi $sp, 3, 14 /* CC::al */, $noreg37 ; CHECK-NEXT: tBcc %bb.1, 1 /* CC::ne */, $cpsr38 ; CHECK-NEXT: tBcc %bb.1, 1 /* CC::ne */, $cpsr39 ; CHECK-NEXT: {{ $}}40 ; CHECK-NEXT: bb.1:41 ; CHECK-NEXT: tBX_RET 14 /* CC::al */, $noreg42 ; CHECK-NEXT: {{ $}}43 ; CHECK-NEXT: bb.2:44 ; CHECK-NEXT: successors: %bb.2(0x80000000)45 ; CHECK-NEXT: {{ $}}46 ; CHECK-NEXT: STRH $sp, $sp, $noreg, 0, 14 /* CC::al */, $noreg47 ; CHECK-NEXT: tB %bb.2, 14 /* CC::al */, $noreg48 bb.0:49 tBcc %bb.2, 1, $cpsr50 51 bb.1:52 $sp = tADDspi $sp, 1, 14, _53 tB %bb.4, 14, $noreg54 55 bb.2:56 $sp = tADDspi $sp, 2, 14, _57 tB %bb.4, 14, $noreg58 59 bb.3:60 STRH $sp, $sp, $noreg, 0, 14, $noreg61 tB %bb.3, 14, $noreg62 63 bb.4:64 $sp = tADDspi $sp, 3, 14, _65 tBcc %bb.5, 1, $cpsr66 tBcc %bb.5, 1, $cpsr67 68 bb.5:69 successors:70 tBX_RET 14, _71...72 73# Similar to the above, but with a triangle.74---75name: avoidMergeBlockTriangle76body: |77 ; CHECK-LABEL: name: avoidMergeBlockTriangle78 ; CHECK: bb.0:79 ; CHECK-NEXT: successors: %bb.1(0x80000000)80 ; CHECK-NEXT: {{ $}}81 ; CHECK-NEXT: $sp = tADDspi $sp, 1, 1 /* CC::ne */, $cpsr82 ; CHECK-NEXT: $sp = tADDspi $sp, 2, 14 /* CC::al */, $noreg83 ; CHECK-NEXT: tBcc %bb.1, 1 /* CC::ne */, $cpsr84 ; CHECK-NEXT: tBcc %bb.1, 1 /* CC::ne */, $cpsr85 ; CHECK-NEXT: {{ $}}86 ; CHECK-NEXT: bb.1:87 ; CHECK-NEXT: tBX_RET 14 /* CC::al */, $noreg88 ; CHECK-NEXT: {{ $}}89 ; CHECK-NEXT: bb.2:90 ; CHECK-NEXT: successors: %bb.2(0x80000000)91 ; CHECK-NEXT: {{ $}}92 ; CHECK-NEXT: STRH $sp, $sp, $noreg, 0, 14 /* CC::al */, $noreg93 ; CHECK-NEXT: tB %bb.2, 14 /* CC::al */, $noreg94 bb.0:95 tBcc %bb.1, 1, $cpsr96 tB %bb.3, 14, $noreg97 98 bb.1:99 $sp = tADDspi $sp, 1, 14, _100 tB %bb.3, 14, $noreg101 102 bb.2:103 STRH $sp, $sp, $noreg, 0, 14, $noreg104 tB %bb.2, 14, $noreg105 106 bb.3:107 $sp = tADDspi $sp, 2, 14, _108 tBcc %bb.4, 1, $cpsr109 tBcc %bb.4, 1, $cpsr110 111 bb.4:112 successors:113 tBX_RET 14, _114...115