[llvm] be6bed4 - [InstCombine] Remove instructions before+after unreachable at same time
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 24 02:10:32 PDT 2025
Author: Nikita Popov
Date: 2025-07-24T11:10:22+02:00
New Revision: be6bed4dc6e346d316a910ee7cb742ece791d855
URL: https://github.com/llvm/llvm-project/commit/be6bed4dc6e346d316a910ee7cb742ece791d855
DIFF: https://github.com/llvm/llvm-project/commit/be6bed4dc6e346d316a910ee7cb742ece791d855.diff
LOG: [InstCombine] Remove instructions before+after unreachable at same time
There is no need to first remove the instructions before and then
the ones after in two different worklist iterations. We don't need
to worry about change reporting here, as the functions do that
themselves.
This avoids the issue in #150338, but not really in a principled
way. It's possible that we will have to allow poison arguments
to lifetime.start/lifetime.end again if this turns out to be a
recurring problem.
Added:
llvm/test/Transforms/InstCombine/pr150338.ll
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 365a9b3aafc9e..0be1034b046b6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1502,8 +1502,7 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) {
// This is a non-terminator unreachable marker. Don't remove it.
if (isa<UndefValue>(Ptr)) {
// Remove guaranteed-to-transfer instructions before the marker.
- if (removeInstructionsBeforeUnreachable(SI))
- return &SI;
+ removeInstructionsBeforeUnreachable(SI);
// Remove all instructions after the marker and handle dead blocks this
// implies.
diff --git a/llvm/test/Transforms/InstCombine/pr150338.ll b/llvm/test/Transforms/InstCombine/pr150338.ll
new file mode 100644
index 0000000000000..2ad454ec60f13
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/pr150338.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+; Make sure this does not crash.
+define void @test(ptr %arg) {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ptr [[ARG:%.*]]) {
+; CHECK-NEXT: store i1 true, ptr poison, align 1
+; CHECK-NEXT: ret void
+;
+ %a = alloca i32
+ store ptr %a, ptr %arg
+ store i1 true, ptr poison
+ call void @llvm.lifetime.end.p0(i64 4, ptr %a)
+ ret void
+}
More information about the llvm-commits
mailing list