llvm.org GIT mirror llvm / e2d151c
[MBB] add a missing corner case in UpdateTerminator() After the block placement, if a block ends with a conditional branch, but the next block is not its successor. The conditional branch should be changed to unconditional branch. This patch fixes PR28307, PR28297, PR28402. Differential Revision: http://reviews.llvm.org/D21811 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274470 91177308-0d34-0410-b5e6-96231b3b80d8 Haicheng Wu 4 years ago
2 changed file(s) with 77 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
469469 FallthroughBB = *SI;
470470 }
471471
472 if (!FallthroughBB && canFallThrough()) {
473 // We fallthrough to the same basic block as the conditional jump targets.
474 // Remove the conditional jump, leaving unconditional fallthrough.
475 // FIXME: This does not seem like a reasonable pattern to support, but it
476 // has been seen in the wild coming out of degenerate ARM test cases.
472 if (!FallthroughBB) {
473 if (canFallThrough()) {
474 // We fallthrough to the same basic block as the conditional jump targets.
475 // Remove the conditional jump, leaving unconditional fallthrough.
476 // FIXME: This does not seem like a reasonable pattern to support, but it
477 // has been seen in the wild coming out of degenerate ARM test cases.
478 TII->RemoveBranch(*this);
479
480 // Finally update the unconditional successor to be reached via a branch if
481 // it would not be reached by fallthrough.
482 if (!isLayoutSuccessor(TBB))
483 TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
484 return;
485 }
486
487 // We enter here iff exactly one successor is TBB which cannot fallthrough
488 // and the rest successors if any are EHPads. In this case, we need to
489 // change the conditional branch into unconditional branch.
477490 TII->RemoveBranch(*this);
478
479 // Finally update the unconditional successor to be reached via a branch if
480 // it would not be reached by fallthrough.
481 if (!isLayoutSuccessor(TBB))
482 TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
491 Cond.clear();
492 TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
483493 return;
484494 }
485495
0 # RUN: llc -march=x86-64 -verify-machineinstrs -run-pass block-placement -o /dev/null %s 2>&1 | FileCheck %s
1 # Check the conditional jump in bb.1 is changed to unconditional after block placement swaps bb.2 and bb.3.
2
3 --- |
4 @a = external global i16
5 @b = external global i32
6
7 ; Function Attrs: nounwind
8 define void @f2() {
9 br i1 undef, label %bb1, label %bb3
10
11 bb1:
12 br i1 undef, label %bb2, label %bb2
13
14 bb2:
15 br label %bb4
16
17 bb3:
18 br label %bb2
19
20 bb4:
21 ret void
22 }
23
24
25 ...
26 ---
27 # CHECK-LABEL: name: f2
28 # CHECK: bb.1:
29 # CHECK: JMP_1 %bb.2
30 # CHECK: bb.3:
31 # CHECK: bb.2:
32 name: f2
33 body: |
34 bb.0 (%ir-block.0):
35 successors: %bb.1(50), %bb.3(50)
36
37 JNE_1 %bb.1, implicit %eflags
38 JMP_1 %bb.3
39 bb.1:
40 successors: %bb.2(100)
41
42 JNE_1 %bb.2, implicit %eflags
43
44 bb.2:
45 successors: %bb.4(100)
46
47 JMP_1 %bb.4
48
49 bb.3:
50 successors: %bb.2(100)
51 JMP_1 %bb.2
52
53 bb.4:
54 RETQ
55
56 ...