1 ; RUN: opt < %s -passes=deadargelim -S | FileCheck %s
3 %Ty = type { i32, i32 }
5 ; sanity check that the argument and return value are both dead
6 ; CHECK-LABEL: define internal void @test1()
8 define internal %Ty* @test1(%Ty* %this) {
12 ; do not keep alive the return value of a function with a dead 'returned' argument
13 ; CHECK-LABEL: define internal void @test2()
15 define internal %Ty* @test2(%Ty* returned %this) {
19 ; dummy to keep 'this' alive
20 @dummy = global %Ty* null
22 ; sanity check that return value is dead
23 ; CHECK-LABEL: define internal void @test3(%Ty* %this)
25 define internal %Ty* @test3(%Ty* %this) {
26 store volatile %Ty* %this, %Ty** @dummy
30 ; keep alive return value of a function if the 'returned' argument is live
31 ; CHECK-LABEL: define internal %Ty* @test4(%Ty* returned %this)
33 define internal %Ty* @test4(%Ty* returned %this) {
34 store volatile %Ty* %this, %Ty** @dummy
38 ; don't do this if 'returned' is on the call site...
39 ; CHECK-LABEL: define internal void @test5(%Ty* %this)
41 define internal %Ty* @test5(%Ty* %this) {
42 store volatile %Ty* %this, %Ty** @dummy
46 define %Ty* @caller(%Ty* %this) {
47 %1 = call %Ty* @test1(%Ty* %this)
48 %2 = call %Ty* @test2(%Ty* %this)
49 %3 = call %Ty* @test3(%Ty* %this)
50 %4 = call %Ty* @test4(%Ty* %this)
51 ; ...instead, drop 'returned' form the call site
52 ; CHECK: call void @test5(%Ty* %this)
53 %5 = call %Ty* @test5(%Ty* returned %this)