Home | History | Annotate | Download | only in DeadArgElim
      1 ; RUN: opt < %s -deadargelim -S | FileCheck %s
      2 
      3 %Ty = type { i32, i32 }
      4 
      5 ; sanity check that the argument and return value are both dead
      6 ; CHECK-LABEL: define internal void @test1()
      7 
      8 define 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 
     15 define 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 ; sanity check that return value is dead
     23 ; CHECK-LABEL: define internal void @test3(%Ty* %this)
     24 
     25 define 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 
     33 define 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 
     41 define internal %Ty* @test5(%Ty* %this) {
     42   store volatile %Ty* %this, %Ty** @dummy
     43   ret %Ty* %this
     44 }
     45 
     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)
     54   ret %Ty* %this
     55 }
     56