llvm.org GIT mirror llvm / f8f42fd
Merging r330345: ------------------------------------------------------------------------ r330345 | kparzysz | 2018-04-19 10:26:46 -0700 (Thu, 19 Apr 2018) | 8 lines [if-converter] Handle BBs that terminate in ret during diamond conversion This fixes https://llvm.org/PR36825. Original patch by Valentin Churavy (D45218). Differential Revision: https://reviews.llvm.org/D45731 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@333561 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 4 months ago
3 changed file(s) with 87 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
17131713 }
17141714
17151715 // Remove the duplicated instructions at the beginnings of both paths.
1716 // Skip dbg_value instructions
1716 // Skip dbg_value instructions.
17171717 MachineBasicBlock::iterator DI1 = MBB1.getFirstNonDebugInstr();
17181718 MachineBasicBlock::iterator DI2 = MBB2.getFirstNonDebugInstr();
17191719 BBI1->NonPredSize -= NumDups1;
17201720 BBI2->NonPredSize -= NumDups1;
17211721
17221722 // Skip past the dups on each side separately since there may be
1723 // differing dbg_value entries.
1723 // differing dbg_value entries. NumDups1 can include a "return"
1724 // instruction, if it's not marked as "branch".
17241725 for (unsigned i = 0; i < NumDups1; ++DI1) {
1726 if (DI1 == MBB1.end())
1727 break;
17251728 if (!DI1->isDebugValue())
17261729 ++i;
17271730 }
17281731 while (NumDups1 != 0) {
17291732 ++DI2;
1733 if (DI2 == MBB2.end())
1734 break;
17301735 if (!DI2->isDebugValue())
17311736 --NumDups1;
17321737 }
17371742 Redefs.stepForward(MI, Dummy);
17381743 }
17391744 }
1745
17401746 BBI.BB->splice(BBI.BB->end(), &MBB1, MBB1.begin(), DI1);
17411747 MBB2.erase(MBB2.begin(), DI2);
17421748
1743 // The branches have been checked to match, so it is safe to remove the branch
1744 // in BB1 and rely on the copy in BB2
1749 // The branches have been checked to match, so it is safe to remove the
1750 // branch in BB1 and rely on the copy in BB2. The complication is that
1751 // the blocks may end with a return instruction, which may or may not
1752 // be marked as "branch". If it's not, then it could be included in
1753 // "dups1", leaving the blocks potentially empty after moving the common
1754 // duplicates.
17451755 #ifndef NDEBUG
17461756 // Unanalyzable branches must match exactly. Check that now.
17471757 if (!BBI1->IsBrAnalyzable)
17671777 if (RemoveBranch)
17681778 BBI2->NonPredSize -= TII->removeBranch(*BBI2->BB);
17691779 else {
1770 do {
1771 assert(DI2 != MBB2.begin());
1772 DI2--;
1773 } while (DI2->isBranch() || DI2->isDebugValue());
1774 DI2++;
1780 // Make DI2 point to the end of the range where the common "tail"
1781 // instructions could be found.
1782 while (DI2 != MBB2.begin()) {
1783 MachineBasicBlock::iterator Prev = std::prev(DI2);
1784 if (!Prev->isBranch() && !Prev->isDebugValue())
1785 break;
1786 DI2 = Prev;
1787 }
17751788 }
17761789 while (NumDups2 != 0) {
17771790 // NumDups2 only counted non-dbg_value instructions, so this won't
18321845 // a non-predicated in BBI2, then we don't want to predicate the one from
18331846 // BBI2. The reason is that if we merged these blocks, we would end up with
18341847 // two predicated terminators in the same block.
1848 // Also, if the branches in MBB1 and MBB2 were non-analyzable, then don't
1849 // predicate them either. They were checked to be identical, and so the
1850 // same branch would happen regardless of which path was taken.
18351851 if (!MBB2.empty() && (DI2 == MBB2.end())) {
18361852 MachineBasicBlock::iterator BBI1T = MBB1.getFirstTerminator();
18371853 MachineBasicBlock::iterator BBI2T = MBB2.getFirstTerminator();
1838 if (BBI1T != MBB1.end() && TII->isPredicated(*BBI1T) &&
1839 BBI2T != MBB2.end() && !TII->isPredicated(*BBI2T))
1854 bool BB1Predicated = BBI1T != MBB1.end() && TII->isPredicated(*BBI1T);
1855 bool BB2NonPredicated = BBI2T != MBB2.end() && !TII->isPredicated(*BBI2T);
1856 if (BB2NonPredicated && (BB1Predicated || !BBI2->IsBrAnalyzable))
18401857 --DI2;
18411858 }
18421859
0 # RUN: llc -march=hexagon -run-pass if-converter %s -o - | FileCheck %s
1
2 # Make sure this gets if-converted and it doesn't crash.
3 # CHECK-LABEL: bb.0
4 # CHECK: PS_jmpret %r31
5 # CHECK-NOT: bb.{{[1-9]+}}:
6
7 ---
8 name: fred
9 tracksRegLiveness: true
10 body: |
11 bb.0:
12 successors: %bb.1, %bb.2
13 liveins: %r0
14 renamable %p0 = C2_cmpeqi killed renamable %r0, 0
15 J2_jumpf killed renamable %p0, %bb.2, implicit-def dead %pc
16
17 bb.1:
18 S4_storeiri_io undef renamable %r0, 0, 32768 :: (store 4 into `i32* undef`)
19 PS_jmpret %r31, implicit-def dead %pc
20
21 bb.2:
22 S4_storeiri_io undef renamable %r0, 0, 32768 :: (store 4 into `i32* undef`)
23 PS_jmpret %r31, implicit-def dead %pc
24 ...
0 # RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -run-pass=if-converter %s -o - | FileCheck %s
1 ---
2 name: foo
3 body: |
4 bb.0:
5 liveins: %x0, %x3
6 successors: %bb.1(0x40000000), %bb.2(0x40000000)
7
8 dead renamable %x3 = ANDIo8 killed renamable %x3, 1, implicit-def dead %cr0, implicit-def %cr0gt
9 %cr2lt = CROR %cr0gt, %cr0gt
10 BCn killed renamable %cr2lt, %bb.2
11 B %bb.1
12
13 bb.1:
14 renamable %x3 = LIS8 4096
15 MTLR8 %x0, implicit-def %lr8
16 BLR8 implicit %lr8, implicit %rm, implicit %x3
17
18 bb.2:
19 renamable %x3 = LIS8 4096
20 MTLR8 %x0, implicit-def %lr8
21 BLR8 implicit %lr8, implicit %rm, implicit %x3
22 ...
23
24 # Diamond testcase with equivalent branches terminating in returns.
25
26 # CHECK: body: |
27 # CHECK: bb.0:
28 # CHECK: dead renamable %x3 = ANDIo8 killed renamable %x3, 1, implicit-def dead %cr0, implicit-def %cr0gt
29 # CHECK: %cr2lt = CROR %cr0gt, %cr0gt
30 # CHECK: renamable %x3 = LIS8 4096
31 # CHECK: MTLR8 %x0, implicit-def %lr8
32 # CHECK: BLR8 implicit %lr8, implicit %rm, implicit %x3
33