[PATCH] D132882: [BOLT] Restrict ICP for functions with unknown control flow

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 29 13:11:23 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

ICP has two modes: jump table promotion and indirect call promotion.
The selection is based on whether an instruction has a jump table or not.
An instruction with unknown control flow doesn't have a jump table and will
fall under indirect call promotion policy which might be incorrect/unsafe
(if an instruction is not a tail call, i.e. has local jump targets).

Prevent ICP for functions containing instructions with unknown control flow.

Follow-up to https://reviews.llvm.org/D128870.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132882

Files:
  bolt/include/bolt/Passes/IndirectCallPromotion.h
  bolt/lib/Passes/IndirectCallPromotion.cpp


Index: bolt/lib/Passes/IndirectCallPromotion.cpp
===================================================================
--- bolt/lib/Passes/IndirectCallPromotion.cpp
+++ bolt/lib/Passes/IndirectCallPromotion.cpp
@@ -1158,8 +1158,7 @@
     for (auto &BFIt : BFs) {
       BinaryFunction &Function = BFIt.second;
 
-      if (!Function.isSimple() || Function.isIgnored() ||
-          !Function.hasProfile())
+      if (!shouldOptimize(Function))
         continue;
 
       const bool HasLayout = !Function.getLayout().block_empty();
@@ -1219,7 +1218,7 @@
   for (BinaryFunction *FuncPtr : Functions) {
     BinaryFunction &Function = *FuncPtr;
 
-    if (!Function.isSimple() || Function.isIgnored() || !Function.hasProfile())
+    if (!shouldOptimize(Function))
       continue;
 
     const bool HasLayout = !Function.getLayout().block_empty();
Index: bolt/include/bolt/Passes/IndirectCallPromotion.h
===================================================================
--- bolt/include/bolt/Passes/IndirectCallPromotion.h
+++ bolt/include/bolt/Passes/IndirectCallPromotion.h
@@ -217,6 +217,10 @@
   bool shouldPrint(const BinaryFunction &BF) const override {
     return BinaryFunctionPass::shouldPrint(BF) && Modified.count(&BF) > 0;
   }
+  bool shouldOptimize(const BinaryFunction &BF) const override {
+    return BF.isSimple() && !BF.isIgnored() && BF.hasProfile() &&
+           !BF.hasUnknownControlFlow();
+  }
   void runOnFunctions(BinaryContext &BC) override;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132882.456447.patch
Type: text/x-patch
Size: 1476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220829/7d8e814e/attachment.bin>


More information about the llvm-commits mailing list