[PATCH] D33037: [IfConversion] Keep the CFG updated incrementally in IfConvertTriangle
Mikael Holmén via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 11 23:42:14 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL302876: [IfConversion] Keep the CFG updated incrementally in IfConvertTriangle (authored by uabelho).
Changed prior to commit:
https://reviews.llvm.org/D33037?vs=98722&id=98727#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33037
Files:
llvm/trunk/lib/CodeGen/IfConversion.cpp
llvm/trunk/test/CodeGen/MIR/ARM/PR32721_ifcvt_triangle_unanalyzable.mir
Index: llvm/trunk/lib/CodeGen/IfConversion.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/IfConversion.cpp
+++ llvm/trunk/lib/CodeGen/IfConversion.cpp
@@ -1588,22 +1588,32 @@
BBCvt = MBPI->getEdgeProbability(BBI.BB, &CvtMBB);
}
+ // To be able to insert code freely at the end of BBI we sometimes remove
+ // the branch from BBI to NextMBB temporarily. Remember if this happened.
+ bool RemovedBranchToNextMBB = false;
if (CvtMBB.pred_size() > 1) {
BBI.NonPredSize -= TII->removeBranch(*BBI.BB);
// Copy instructions in the true block, predicate them, and add them to
// the entry block.
CopyAndPredicateBlock(BBI, *CvtBBI, Cond, true);
- // RemoveExtraEdges won't work if the block has an unanalyzable branch, so
- // explicitly remove CvtBBI as a successor.
+ // Keep the CFG updated.
BBI.BB->removeSuccessor(&CvtMBB, true);
} else {
// Predicate the 'true' block after removing its branch.
CvtBBI->NonPredSize -= TII->removeBranch(CvtMBB);
PredicateBlock(*CvtBBI, CvtMBB.end(), Cond);
- // Now merge the entry of the triangle with the true block.
+ // Remove the branch from the entry of the triangle to NextBB to be able to
+ // do the merge below. Keep the CFG updated, but remember we removed the
+ // branch since we do want to execute NextMBB, either by introducing a
+ // branch to it again, or merging it into the entry block.
+ // How it's handled is decided further down.
BBI.NonPredSize -= TII->removeBranch(*BBI.BB);
+ BBI.BB->removeSuccessor(&NextMBB, true);
+ RemovedBranchToNextMBB = true;
+
+ // Now merge the entry of the triangle with the true block.
MergeBlocks(BBI, *CvtBBI, false);
}
@@ -1641,21 +1651,26 @@
// block. By not merging them, we make it possible to iteratively
// ifcvt the blocks.
if (!HasEarlyExit &&
- NextMBB.pred_size() == 1 && !NextBBI->HasFallThrough &&
+ // We might have removed BBI from NextMBB's predecessor list above but
+ // we want it to be there, so consider that too.
+ (NextMBB.pred_size() == (RemovedBranchToNextMBB ? 0 : 1)) &&
+ !NextBBI->HasFallThrough &&
!NextMBB.hasAddressTaken()) {
+ // We will merge NextBBI into BBI, and thus remove the current
+ // fallthrough from BBI into CvtBBI.
+ BBI.BB->removeSuccessor(&CvtMBB, true);
MergeBlocks(BBI, *NextBBI);
FalseBBDead = true;
} else {
InsertUncondBranch(*BBI.BB, NextMBB, TII);
+ BBI.BB->addSuccessor(&NextMBB);
BBI.HasFallThrough = false;
}
// Mixed predicated and unpredicated code. This cannot be iteratively
// predicated.
IterIfcvt = false;
}
- RemoveExtraEdges(BBI);
-
// Update block info. BB can be iteratively if-converted.
if (!IterIfcvt)
BBI.IsDone = true;
Index: llvm/trunk/test/CodeGen/MIR/ARM/PR32721_ifcvt_triangle_unanalyzable.mir
===================================================================
--- llvm/trunk/test/CodeGen/MIR/ARM/PR32721_ifcvt_triangle_unanalyzable.mir
+++ llvm/trunk/test/CodeGen/MIR/ARM/PR32721_ifcvt_triangle_unanalyzable.mir
@@ -0,0 +1,24 @@
+# RUN: llc -mtriple=arm-apple-ios -run-pass=if-converter %s -o - | FileCheck %s
+---
+name: foo
+body: |
+ bb.0:
+ B %bb.2
+
+ bb.1:
+ BX_RET 14, 0
+
+ bb.2:
+ Bcc %bb.1, 1, %cpsr
+
+ bb.3:
+ B %bb.1
+
+...
+
+# We should get a single block containing the BX_RET, with no successors at all
+
+# CHECK: body:
+# CHECK-NEXT: bb.0:
+# CHECK-NEXT: BX_RET
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33037.98727.patch
Type: text/x-patch
Size: 3615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170512/33e273d6/attachment.bin>
More information about the llvm-commits
mailing list