[PATCH] D70929: Don't extract code containing an indirect jump from a callbr

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 2 15:16:07 PST 2019


void created this revision.
void added reviewers: compnerd, vsk, tejohnson.
void added a project: LLVM.

The callbr instruction's indirect destinations are expected to be within
the current function. Extracting them will cause chaos as the callbr
will then want to branch to a label in another function, which isn't
allowed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70929

Files:
  llvm/lib/Transforms/IPO/HotColdSplitting.cpp


Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp
===================================================================
--- llvm/lib/Transforms/IPO/HotColdSplitting.cpp
+++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp
@@ -129,6 +129,13 @@
 
 /// Check whether it's safe to outline \p BB.
 static bool mayExtractBlock(const BasicBlock &BB) {
+  // Don't extract the indirect destination of a "callbr" instruction as even
+  // though it's ice cold it's not safe to extract it, for reasons similar to
+  // extracting an EH block.
+  for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI)
+    if (isa<CallBrInst>(PI->getTerminator()))
+      return false;
+
   // EH pads are unsafe to outline because doing so breaks EH type tables. It
   // follows that invoke instructions cannot be extracted, because CodeExtractor
   // requires unwind destinations to be within the extraction region.
@@ -137,7 +144,7 @@
   // be unreachable. It’s not safe to split them out either.
   auto Term = BB.getTerminator();
   return !BB.hasAddressTaken() && !BB.isEHPad() && !isa<InvokeInst>(Term) &&
-         !isa<ResumeInst>(Term);
+         !isa<ResumeInst>(Term) && !isa<CallBrInst>(Term);
 }
 
 /// Mark \p F cold. Based on this assumption, also optimize it for minimum size.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70929.231787.patch
Type: text/x-patch
Size: 1287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191202/52accd77/attachment.bin>


More information about the llvm-commits mailing list