[llvm] cbce5ed - [Inliner][NFC] Simplify blockaddress checks (#176044)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 19 10:37:11 PST 2026


Author: Aniket Singh
Date: 2026-01-19T10:37:06-08:00
New Revision: cbce5ed87306b117460dc2fe607e70251e4958ea

URL: https://github.com/llvm/llvm-project/commit/cbce5ed87306b117460dc2fe607e70251e4958ea
DIFF: https://github.com/llvm/llvm-project/commit/cbce5ed87306b117460dc2fe607e70251e4958ea.diff

LOG: [Inliner][NFC] Simplify blockaddress checks (#176044)

The exception for callbr dates back to an earlier time when callbr used
blockaddress. It no longer does, so the callbr exception is no longer
valid.

This patch removes the exception and simplifies the check. It now
rejects inlining immediately if a block address is taken, rather than
iterating through users.

Co-authored-by: Aniket Singh <amiket.singh.3200.00 at gmail.com>

Added: 
    

Modified: 
    llvm/lib/Analysis/InlineCost.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 5169b43834edc..0e49b1903d410 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -2980,7 +2980,7 @@ InlineResult CallAnalyzer::analyze() {
 
     onBlockStart(BB);
 
-    // Disallow inlining a blockaddress with uses other than strictly callbr.
+    // Disallow inlining a blockaddress.
     // A blockaddress only has defined behavior for an indirect branch in the
     // same function, and we do not currently support inlining indirect
     // branches.  But, the inliner may not see an indirect branch that ends up
@@ -2989,9 +2989,7 @@ InlineResult CallAnalyzer::analyze() {
     // invalid cross-function reference.
     // FIXME: pr/39560: continue relaxing this overt restriction.
     if (BB->hasAddressTaken())
-      for (User *U : BlockAddress::get(&*BB)->users())
-        if (!isa<CallBrInst>(*U))
-          return InlineResult::failure("blockaddress used outside of callbr");
+      return InlineResult::failure("blockaddress used");
 
     // Analyze the cost of this block. If we blow through the threshold, this
     // returns false, and we can bail on out.
@@ -3320,12 +3318,9 @@ InlineResult llvm::isInlineViable(Function &F) {
     if (isa<IndirectBrInst>(BB.getTerminator()))
       return InlineResult::failure("contains indirect branches");
 
-    // Disallow inlining of blockaddresses which are used by non-callbr
-    // instructions.
+    // Disallow inlining of blockaddresses.
     if (BB.hasAddressTaken())
-      for (User *U : BlockAddress::get(&BB)->users())
-        if (!isa<CallBrInst>(*U))
-          return InlineResult::failure("blockaddress used outside of callbr");
+      return InlineResult::failure("blockaddress used");
 
     for (auto &II : BB) {
       CallBase *Call = dyn_cast<CallBase>(&II);


        


More information about the llvm-commits mailing list