[PATCH] D128870: [BOLT] Don't apply ICP to instructions with unknown control flow

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 19:14:19 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: 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 instructions with unknown control flow by adding a corresponding
check in `canPromoteCallsite`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128870

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


Index: bolt/lib/Passes/IndirectCallPromotion.cpp
===================================================================
--- bolt/lib/Passes/IndirectCallPromotion.cpp
+++ bolt/lib/Passes/IndirectCallPromotion.cpp
@@ -947,6 +947,8 @@
 
   if (BB.getKnownExecutionCount() < opts::ExecutionCountThreshold)
     return 0;
+  if (BC.MIB->isUnknownControlFlow(Inst))
+    return 0;
 
   const bool IsJumpTable = BF->getJumpTable(Inst);
 
Index: bolt/include/bolt/Core/MCPlusBuilder.h
===================================================================
--- bolt/include/bolt/Core/MCPlusBuilder.h
+++ bolt/include/bolt/Core/MCPlusBuilder.h
@@ -370,6 +370,11 @@
     return Analysis->isIndirectBranch(Inst);
   }
 
+  virtual bool isUnknownControlFlow(const MCInst &Inst) const {
+    return (isIndirectBranch(Inst) || isIndirectCall(Inst)) &&
+           !getJumpTable(Inst);
+  }
+
   /// Returns true if the instruction is memory indirect call or jump
   virtual bool isBranchOnMem(const MCInst &Inst) const {
     llvm_unreachable("not implemented");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128870.441231.patch
Type: text/x-patch
Size: 1042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220630/7a60fccb/attachment.bin>


More information about the llvm-commits mailing list