xref: /llvm-project/llvm/test/Transforms/DeadArgElim/keepalive.ll (revision 055fb7795aa219a3d274d280ec9129784f169f56)
1e76ecbb0SBjorn Pettersson; RUN: opt < %s -passes=deadargelim -S | FileCheck %s
2cee313d2SEric Christopher
38a887556SArthur Eubanksdeclare token @llvm.call.preallocated.setup(i32)
4*055fb779SNikita Popovdeclare ptr @llvm.call.preallocated.arg(token, i32)
58a887556SArthur Eubanks
6cee313d2SEric Christopher%Ty = type <{ i32, i32 }>
7cee313d2SEric Christopher
8cee313d2SEric Christopher; Check if the pass doesn't modify anything that doesn't need changing. We feed
9cee313d2SEric Christopher; an unused argument to each function to lure it into changing _something_ about
10cee313d2SEric Christopher; the function and then changing too much.
11cee313d2SEric Christopher
12cee313d2SEric Christopher; This checks if the return value attributes are not removed
13fbfb1c79Ssstefan1; CHECK: define internal zeroext i32 @test1() #1
14cee313d2SEric Christopherdefine internal zeroext i32 @test1(i32 %DEADARG1) nounwind {
15fbfb1c79Ssstefan1;
16fbfb1c79Ssstefan1;
17cee313d2SEric Christopher  ret i32 1
18cee313d2SEric Christopher}
19cee313d2SEric Christopher
20cee313d2SEric Christopher; This checks if the struct doesn't get non-packed
21cee313d2SEric Christopher; CHECK-LABEL: define internal <{ i32, i32 }> @test2(
22cee313d2SEric Christopherdefine internal <{ i32, i32 }> @test2(i32 %DEADARG1) {
23fbfb1c79Ssstefan1;
24fbfb1c79Ssstefan1;
25cee313d2SEric Christopher  ret <{ i32, i32 }> <{ i32 1, i32 2 }>
26cee313d2SEric Christopher}
27cee313d2SEric Christopher
28cee313d2SEric Christopher; We use this external function to make sure the return values don't become dead
29cee313d2SEric Christopherdeclare void @user(i32, <{ i32, i32 }>)
30cee313d2SEric Christopher
31cee313d2SEric Christopherdefine void @caller() {
32fbfb1c79Ssstefan1;
33fbfb1c79Ssstefan1;
34cee313d2SEric Christopher  %B = call i32 @test1(i32 1)
35cee313d2SEric Christopher  %C = call <{ i32, i32 }> @test2(i32 2)
36cee313d2SEric Christopher  call void @user(i32 %B, <{ i32, i32 }> %C)
37cee313d2SEric Christopher  ret void
38cee313d2SEric Christopher}
39cee313d2SEric Christopher
40cee313d2SEric Christopher; We can't remove 'this' here, as that would put argmem in ecx instead of
41cee313d2SEric Christopher; memory.
42*055fb779SNikita Popovdefine internal x86_thiscallcc i32 @unused_this(ptr %this, ptr inalloca(i32) %argmem) {
43fbfb1c79Ssstefan1;
44fbfb1c79Ssstefan1;
45*055fb779SNikita Popov  %v = load i32, ptr %argmem
46cee313d2SEric Christopher  ret i32 %v
47cee313d2SEric Christopher}
48*055fb779SNikita Popov; CHECK-LABEL: define internal x86_thiscallcc i32 @unused_this(ptr %this, ptr inalloca(i32) %argmem)
49cee313d2SEric Christopher
50cee313d2SEric Christopherdefine i32 @caller2() {
51fbfb1c79Ssstefan1;
52fbfb1c79Ssstefan1;
53cee313d2SEric Christopher  %t = alloca i32
54cee313d2SEric Christopher  %m = alloca inalloca i32
55*055fb779SNikita Popov  store i32 42, ptr %m
56*055fb779SNikita Popov  %v = call x86_thiscallcc i32 @unused_this(ptr %t, ptr inalloca(i32) %m)
57cee313d2SEric Christopher  ret i32 %v
58cee313d2SEric Christopher}
59cee313d2SEric Christopher
608a887556SArthur Eubanks; We can't remove 'this' here, as that would put argmem in ecx instead of
618a887556SArthur Eubanks; memory.
62*055fb779SNikita Popovdefine internal x86_thiscallcc i32 @unused_this_preallocated(ptr %this, ptr preallocated(i32) %argmem) {
63fbfb1c79Ssstefan1;
64fbfb1c79Ssstefan1;
65*055fb779SNikita Popov  %v = load i32, ptr %argmem
668a887556SArthur Eubanks  ret i32 %v
678a887556SArthur Eubanks}
68*055fb779SNikita Popov; CHECK-LABEL: define internal x86_thiscallcc i32 @unused_this_preallocated(ptr %this, ptr preallocated(i32) %argmem)
698a887556SArthur Eubanks
708a887556SArthur Eubanksdefine i32 @caller3() {
71fbfb1c79Ssstefan1;
72fbfb1c79Ssstefan1;
738a887556SArthur Eubanks  %t = alloca i32
748a887556SArthur Eubanks  %c = call token @llvm.call.preallocated.setup(i32 1)
75*055fb779SNikita Popov  %M = call ptr @llvm.call.preallocated.arg(token %c, i32 0) preallocated(i32)
76*055fb779SNikita Popov  store i32 42, ptr %M
77*055fb779SNikita Popov  %v = call x86_thiscallcc i32 @unused_this_preallocated(ptr %t, ptr preallocated(i32) %M) ["preallocated"(token %c)]
788a887556SArthur Eubanks  ret i32 %v
798a887556SArthur Eubanks}
808a887556SArthur Eubanks
81a81fff8aSJohannes Doerfert; CHECK: attributes #0 = { nocallback nofree nosync nounwind willreturn }
82fbfb1c79Ssstefan1; CHECK: attributes #1 = { nounwind }
83