returned.ll 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ; RUN: opt < %s -deadargelim -S | FileCheck %s
  2. %Ty = type { i32, i32 }
  3. ; sanity check that the argument and return value are both dead
  4. ; CHECK-LABEL: define internal void @test1()
  5. define internal %Ty* @test1(%Ty* %this) {
  6. ret %Ty* %this
  7. }
  8. ; do not keep alive the return value of a function with a dead 'returned' argument
  9. ; CHECK-LABEL: define internal void @test2()
  10. define internal %Ty* @test2(%Ty* returned %this) {
  11. ret %Ty* %this
  12. }
  13. ; dummy to keep 'this' alive
  14. @dummy = global %Ty* null
  15. ; sanity check that return value is dead
  16. ; CHECK-LABEL: define internal void @test3(%Ty* %this)
  17. define internal %Ty* @test3(%Ty* %this) {
  18. store volatile %Ty* %this, %Ty** @dummy
  19. ret %Ty* %this
  20. }
  21. ; keep alive return value of a function if the 'returned' argument is live
  22. ; CHECK-LABEL: define internal %Ty* @test4(%Ty* returned %this)
  23. define internal %Ty* @test4(%Ty* returned %this) {
  24. store volatile %Ty* %this, %Ty** @dummy
  25. ret %Ty* %this
  26. }
  27. ; don't do this if 'returned' is on the call site...
  28. ; CHECK-LABEL: define internal void @test5(%Ty* %this)
  29. define internal %Ty* @test5(%Ty* %this) {
  30. store volatile %Ty* %this, %Ty** @dummy
  31. ret %Ty* %this
  32. }
  33. define %Ty* @caller(%Ty* %this) {
  34. %1 = call %Ty* @test1(%Ty* %this)
  35. %2 = call %Ty* @test2(%Ty* %this)
  36. %3 = call %Ty* @test3(%Ty* %this)
  37. %4 = call %Ty* @test4(%Ty* %this)
  38. ; ...instead, drop 'returned' form the call site
  39. ; CHECK: call void @test5(%Ty* %this)
  40. %5 = call %Ty* @test5(%Ty* returned %this)
  41. ret %Ty* %this
  42. }