1; RUN: opt < %s -passes=deadargelim -S | FileCheck %s
2
3%Ty = type { i32, i32 }
4
5; Validate that the argument and return value are both dead
6; CHECK-LABEL: define internal void @test1()
7
8define internal %Ty* @test1(%Ty* %this) {
9  ret %Ty* %this
10}
11
12; do not keep alive the return value of a function with a dead 'returned' argument
13; CHECK-LABEL: define internal void @test2()
14
15define internal %Ty* @test2(%Ty* returned %this) {
16  ret %Ty* %this
17}
18
19; dummy to keep 'this' alive
20@dummy = global %Ty* null
21
22; Validate that return value is dead
23; CHECK-LABEL: define internal void @test3(%Ty* %this)
24
25define internal %Ty* @test3(%Ty* %this) {
26  store volatile %Ty* %this, %Ty** @dummy
27  ret %Ty* %this
28}
29
30; keep alive return value of a function if the 'returned' argument is live
31; CHECK-LABEL: define internal %Ty* @test4(%Ty* returned %this)
32
33define internal %Ty* @test4(%Ty* returned %this) {
34  store volatile %Ty* %this, %Ty** @dummy
35  ret %Ty* %this
36}
37
38; don't do this if 'returned' is on the call site...
39; CHECK-LABEL: define internal void @test5(%Ty* %this)
40
41define internal %Ty* @test5(%Ty* %this) {
42  store volatile %Ty* %this, %Ty** @dummy
43  ret %Ty* %this
44}
45
46; Drop all these attributes
47; CHECK-LABEL: define internal void @test6
48define internal align 8 dereferenceable_or_null(2) noundef noalias i8* @test6() {
49  ret i8* null
50}
51
52define %Ty* @caller(%Ty* %this) {
53  %1 = call %Ty* @test1(%Ty* %this)
54  %2 = call %Ty* @test2(%Ty* %this)
55  %3 = call %Ty* @test3(%Ty* %this)
56  %4 = call %Ty* @test4(%Ty* %this)
57; ...instead, drop 'returned' form the call site
58; CHECK: call void @test5(%Ty* %this)
59  %5 = call %Ty* @test5(%Ty* returned %this)
60  %6 = call i8* @test6()
61  ret %Ty* %this
62}
63