[PATCH] D149130: [PartialInlining] Fix incorrect costing when IR has unreachable BBs
Vedant Paranjape via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 5 03:09:07 PDT 2023
vedant-amd updated this revision to Diff 519789.
vedant-amd added a comment.
Removed pass wide unreachable block elimination added a depth_first approach to iterate over basic blocks
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
@@ -50,6 +50,7 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/CodeExtractor.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
+#include "llvm/ADT/DepthFirstIterator.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
@@ -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.519789.patch
Type: text/x-patch
Size: 2641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230505/2e0110e7/attachment.bin>
More information about the llvm-commits
mailing list