[llvm] 4923b4d - [Local] Check for null VH in RecursivelyDeleteTriviallyDeadInstructionsPermissive()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 24 04:56:15 PDT 2023
Author: Nikita Popov
Date: 2023-03-24T12:56:06+01:00
New Revision: 4923b4dbaca386b532c80f0572c2d6a0547a2a3d
URL: https://github.com/llvm/llvm-project/commit/4923b4dbaca386b532c80f0572c2d6a0547a2a3d
DIFF: https://github.com/llvm/llvm-project/commit/4923b4dbaca386b532c80f0572c2d6a0547a2a3d.diff
LOG: [Local] Check for null VH in RecursivelyDeleteTriviallyDeadInstructionsPermissive()
Peculiarly, the non-permissive variant handled this gracefully,
but the permissive one did not.
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/ArgumentPromotion/propagate-remove-dead-args.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 31deb08d45989..848db3fe565c1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -555,7 +555,7 @@ bool llvm::RecursivelyDeleteTriviallyDeadInstructionsPermissive(
std::function<void(Value *)> AboutToDeleteCallback) {
unsigned S = 0, E = DeadInsts.size(), Alive = 0;
for (; S != E; ++S) {
- auto *I = dyn_cast<Instruction>(DeadInsts[S]);
+ auto *I = dyn_cast_or_null<Instruction>(DeadInsts[S]);
if (!I || !isInstructionTriviallyDead(I)) {
DeadInsts[S] = nullptr;
++Alive;
diff --git a/llvm/test/Transforms/ArgumentPromotion/propagate-remove-dead-args.ll b/llvm/test/Transforms/ArgumentPromotion/propagate-remove-dead-args.ll
index 4176a8a7bc5c8..87a14533cfda2 100644
--- a/llvm/test/Transforms/ArgumentPromotion/propagate-remove-dead-args.ll
+++ b/llvm/test/Transforms/ArgumentPromotion/propagate-remove-dead-args.ll
@@ -57,3 +57,20 @@ entry:
ret void
}
+define internal ptr @callee(ptr %dead) {
+; CHECK-LABEL: define internal ptr @callee() {
+; CHECK-NEXT: ret ptr null
+;
+ ret ptr null
+}
+
+define void @caller() {
+; CHECK-LABEL: define void @caller() {
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @callee()
+; CHECK-NEXT: [[TMP2:%.*]] = call ptr @callee()
+; CHECK-NEXT: ret void
+;
+ %ret = call ptr @callee(ptr null)
+ %ret2 = call ptr @callee(ptr %ret)
+ ret void
+}
More information about the llvm-commits
mailing list