xref: /llvm-project/llvm/test/Transforms/DeadStoreElimination/nounwind-invoke.ll (revision f497a00da968b0ff90d8c98caa184d14b9a92495)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --prefix-filecheck-ir-name abc
2; RUN: opt -passes=dse -S < %s | FileCheck %s
3
4; Make sure invokes are not removed as dead stores.
5define void @test_nounwind_invoke() personality ptr @__gxx_personality_v0 {
6; CHECK-LABEL: @test_nounwind_invoke(
7; CHECK-NEXT:  bb:
8; CHECK-NEXT:    [[TMP:%.*]] = alloca i32, align 4
9; CHECK-NEXT:    invoke void @foo(ptr [[TMP]])
10; CHECK-NEXT:    to label [[BB1:%.*]] unwind label [[BB2:%.*]]
11; CHECK:       bb1:
12; CHECK-NEXT:    call void @llvm.lifetime.end.p0(i64 4, ptr [[TMP]])
13; CHECK-NEXT:    ret void
14; CHECK:       bb2:
15; CHECK-NEXT:    [[ABCTMP1:%.*]] = landingpad { ptr, i32 }
16; CHECK-NEXT:    cleanup
17; CHECK-NEXT:    resume { ptr, i32 } [[ABCTMP1]]
18;
19bb:
20  %tmp = alloca i32, align 4
21  ; 'foo' is 'argmemonly', meaning it can only write to memory pointed by %tmp.
22  ; And this def is killed by 'call @llvm.lifetime.end.p0' in bb1 without
23  ; being used elsewhere, becoming a dead store. But we shouldn't remove this
24  ; because invokes are terminators and thus cannot be removed.
25  invoke void @foo(ptr %tmp)
26  to label %bb1 unwind label %bb2
27
28bb1:                                              ; preds = %bb
29  call void @llvm.lifetime.end.p0(i64 4, ptr %tmp)
30  ret void
31
32bb2:                                              ; preds = %bb
33  %tmp1 = landingpad { ptr, i32 }
34  cleanup
35  resume { ptr, i32 } %tmp1
36}
37
38; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
39declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0
40; Function Attrs: argmemonly nounwind willreturn
41declare void @foo(ptr) #1
42declare i32 @__gxx_personality_v0(...)
43
44attributes #0 = { argmemonly nocallback nofree nosync nounwind willreturn }
45attributes #1 = { argmemonly nounwind willreturn }
46