Skip to content

Commit be6bed4

Browse files
committed
[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.
1 parent 98562ff commit be6bed4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,8 +1502,7 @@ Instruction *InstCombinerImpl::visitStoreInst(StoreInst &SI) {
15021502
// This is a non-terminator unreachable marker. Don't remove it.
15031503
if (isa<UndefValue>(Ptr)) {
15041504
// Remove guaranteed-to-transfer instructions before the marker.
1505-
if (removeInstructionsBeforeUnreachable(SI))
1506-
return &SI;
1505+
removeInstructionsBeforeUnreachable(SI);
15071506

15081507
// Remove all instructions after the marker and handle dead blocks this
15091508
// implies.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
3+
4+
; Make sure this does not crash.
5+
define void @test(ptr %arg) {
6+
; CHECK-LABEL: define void @test(
7+
; CHECK-SAME: ptr [[ARG:%.*]]) {
8+
; CHECK-NEXT: store i1 true, ptr poison, align 1
9+
; CHECK-NEXT: ret void
10+
;
11+
%a = alloca i32
12+
store ptr %a, ptr %arg
13+
store i1 true, ptr poison
14+
call void @llvm.lifetime.end.p0(i64 4, ptr %a)
15+
ret void
16+
}

0 commit comments

Comments
 (0)