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 ptr @test1(ptr %this) { 9 ret ptr %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 ptr @test2(ptr returned %this) { 16 ret ptr %this 17} 18 19; dummy to keep 'this' alive 20@dummy = global ptr null 21 22; Validate that return value is dead 23; CHECK-LABEL: define internal void @test3(ptr %this) 24 25define internal ptr @test3(ptr %this) { 26 store volatile ptr %this, ptr @dummy 27 ret ptr %this 28} 29 30; keep alive return value of a function if the 'returned' argument is live 31; CHECK-LABEL: define internal ptr @test4(ptr returned %this) 32 33define internal ptr @test4(ptr returned %this) { 34 store volatile ptr %this, ptr @dummy 35 ret ptr %this 36} 37 38; don't do this if 'returned' is on the call site... 39; CHECK-LABEL: define internal void @test5(ptr %this) 40 41define internal ptr @test5(ptr %this) { 42 store volatile ptr %this, ptr @dummy 43 ret ptr %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 ptr @test6() { 49 ret ptr null 50} 51 52define ptr @caller(ptr %this) { 53 %1 = call ptr @test1(ptr %this) 54 %2 = call ptr @test2(ptr %this) 55 %3 = call ptr @test3(ptr %this) 56 %4 = call ptr @test4(ptr %this) 57; ...instead, drop 'returned' form the call site 58; CHECK: call void @test5(ptr %this) 59 %5 = call ptr @test5(ptr returned %this) 60 %6 = call ptr @test6() 61 ret ptr %this 62} 63