[PATCH] D123870: [LoopDeletion] Don't delete loops with blocks that have their address taken
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 15 12:44:01 PDT 2022
aeubanks created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Otherwise we may end up making the blockaddress invalid and passing it to other functions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D123870
Files:
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
llvm/test/Transforms/LoopDeletion/blockaddress.ll
Index: llvm/test/Transforms/LoopDeletion/blockaddress.ll
===================================================================
--- llvm/test/Transforms/LoopDeletion/blockaddress.ll
+++ llvm/test/Transforms/LoopDeletion/blockaddress.ll
@@ -6,11 +6,13 @@
declare void @g(ptr)
;.
-; CHECK: @[[BA:[a-zA-Z0-9_$"\\.-]+]] = private constant ptr inttoptr (i32 1 to ptr)
+; CHECK: @[[BA:[a-zA-Z0-9_$"\\.-]+]] = private constant ptr blockaddress(@f, [[BB:%.*]])
;.
define void @f() {
; CHECK-LABEL: @f(
; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[BB:%.*]]
+; CHECK: bb:
; CHECK-NEXT: br label [[BB2:%.*]]
; CHECK: bb2:
; CHECK-NEXT: call void @g(ptr @ba)
Index: llvm/lib/Transforms/Scalar/LoopDeletion.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -58,6 +58,11 @@
return LoopDeletionResult::Unmodified;
}
+static bool loopHasAddressTaken(Loop *L) {
+ return any_of(L->blocks(),
+ [](BasicBlock *BB) { return BB->hasAddressTaken(); });
+}
+
/// Determines if a loop is dead.
///
/// This assumes that we've already checked for unique exit and exiting blocks,
@@ -453,6 +458,11 @@
return LoopDeletionResult::Unmodified;
}
+ if (loopHasAddressTaken(L)) {
+ LLVM_DEBUG(dbgs() << "Loop has address taken, cannot delete.\n");
+ return LoopDeletionResult::Unmodified;
+ }
+
BasicBlock *ExitBlock = L->getUniqueExitBlock();
if (ExitBlock && isLoopNeverExecuted(L)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123870.423154.patch
Type: text/x-patch
Size: 1559 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220415/133cfa89/attachment.bin>
More information about the llvm-commits
mailing list