From 81d32846b03a7de6dd7cfe699093ac23bdb237c3 Mon Sep 17 00:00:00 2001 From: Kyle Butt Date: Wed, 10 Aug 2016 21:03:27 +0000 Subject: Codegen: Don't tail-duplicate blocks with un-analyzable fallthrough. If AnalyzeBranch can't analyze a block and it is possible to fallthrough, then duplicating the block doesn't make sense, as only one block can be the layout predecessor for the un-analyzable fallthrough. Submitted wit a test case, but NOTE: the test case doesn't currently fail. However, the test case fails with D20505 and would have saved me some time debugging. llvm-svn: 278288 --- llvm/lib/CodeGen/TailDuplicator.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'llvm/lib/CodeGen/TailDuplicator.cpp') diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index 059c1dc5483..029bd138f53 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -525,6 +525,16 @@ bool TailDuplicator::shouldTailDuplicate(const MachineFunction &MF, else MaxDuplicateCount = TailDuplicateSize; + // If the block to be duplicated ends in an unanalyzable fallthrough, don't + // duplicate it. + // A similar check is necessary in MachineBlockPlacement to make sure pairs of + // blocks with unanalyzable fallthrough get layed out contiguously. + MachineBasicBlock *PredTBB = nullptr, *PredFBB = nullptr; + SmallVector PredCond; + if (TII->analyzeBranch(TailBB, PredTBB, PredFBB, PredCond, true) + && TailBB.canFallThrough()) + return false; + // If the target has hardware branch prediction that can handle indirect // branches, duplicating them can often make them predictable when there // are common paths through the code. The limit needs to be high enough -- cgit v1.2.3