[PATCH] D149130: [PartialInlining] Fix incorrect costing when IR has unreachable BBs

Vedant Paranjape via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 9 04:59:20 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG438e1cff7bfb: [PartialInlining] Fix incorrect costing when IR has unreachable BBs (authored by vedant-amd).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149130/new/

https://reviews.llvm.org/D149130

Files:
  llvm/lib/Transforms/IPO/PartialInlining.cpp
  llvm/test/Transforms/PartialInlining/unreachable_basic_block.ll


Index: llvm/test/Transforms/PartialInlining/unreachable_basic_block.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/PartialInlining/unreachable_basic_block.ll
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=partial-inliner -S < %s | FileCheck %s
+declare i1 @llvm.public.type.test(ptr, metadata)
+
+define void @dummy() {
+; CHECK-LABEL: @dummy(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br i1 false, label [[WHILE_END:%.*]], label [[WHILE_BODY:%.*]]
+; CHECK:       while.body:
+; CHECK-NEXT:    call void @dummy.1.while.body()
+; CHECK-NEXT:    br label [[WHILE_END]]
+; CHECK:       while.end:
+; CHECK-NEXT:    ret void
+;
+entry:
+  br i1 false, label %while.end, label %while.body
+
+while.body:                                       ; preds = %entry
+  call void @dummy()
+  br label %while.end
+
+unreachable.block:               ; No predecessors!
+  %0 = tail call i1 @llvm.public.type.test(ptr null, metadata !"test-function")
+  %result = getelementptr ptr, ptr null, i64 1
+  br label %while.end
+
+while.end:                                        ; preds = %unreachable.block, %while.body, %entry
+  ret void
+}
Index: llvm/lib/Transforms/IPO/PartialInlining.cpp
===================================================================
--- llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -14,6 +14,7 @@
 #include "llvm/Transforms/IPO/PartialInlining.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
@@ -1178,14 +1179,14 @@
   ToExtract.push_back(ClonedOI->NonReturnBlock);
   OutlinedRegionCost += PartialInlinerImpl::computeBBInlineCost(
       ClonedOI->NonReturnBlock, ClonedFuncTTI);
-  for (BasicBlock &BB : *ClonedFunc)
-    if (!ToBeInlined(&BB) && &BB != ClonedOI->NonReturnBlock) {
-      ToExtract.push_back(&BB);
+  for (BasicBlock *BB : depth_first(&ClonedFunc->getEntryBlock()))
+    if (!ToBeInlined(BB) && BB != ClonedOI->NonReturnBlock) {
+      ToExtract.push_back(BB);
       // FIXME: the code extractor may hoist/sink more code
       // into the outlined function which may make the outlining
       // overhead (the difference of the outlined function cost
       // and OutliningRegionCost) look larger.
-      OutlinedRegionCost += computeBBInlineCost(&BB, ClonedFuncTTI);
+      OutlinedRegionCost += computeBBInlineCost(BB, ClonedFuncTTI);
     }
 
   // Extract the body of the if.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149130.520659.patch
Type: text/x-patch
Size: 2652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230509/dbce3826/attachment.bin>


More information about the llvm-commits mailing list