diff options
| author | Johannes Doerfert <johannes@jdoerfert.de> | 2019-10-14 17:29:05 -0500 |
|---|---|---|
| committer | Johannes Doerfert <johannes@jdoerfert.de> | 2019-10-30 20:57:57 -0500 |
| commit | 0be9cf2da9c1400eea720f0c6bead3df07c98a9c (patch) | |
| tree | b167c09aef7de64ee195f56869983a646c9210aa /llvm/test/Transforms | |
| parent | ed7bcb2cb1575d26bd9161103fae01d1a5fa4b07 (diff) | |
| download | bcm5719-llvm-0be9cf2da9c1400eea720f0c6bead3df07c98a9c.tar.gz bcm5719-llvm-0be9cf2da9c1400eea720f0c6bead3df07c98a9c.zip | |
[Attributor] Add "free"-based heap2stack deduction
Summary:
If there is a unique free of the allocated that has to be reached from
the malloc, we can apply the heap-2-stack transformation even if the
pointer escapes.
Reviewers: hfinkel, sstefan1, uenoku
Subscribers: hiraditya, bollu, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68958
Diffstat (limited to 'llvm/test/Transforms')
| -rw-r--r-- | llvm/test/Transforms/FunctionAttrs/heap_to_stack.ll | 28 | ||||
| -rw-r--r-- | llvm/test/Transforms/FunctionAttrs/noalias_returned.ll | 20 |
2 files changed, 34 insertions, 14 deletions
diff --git a/llvm/test/Transforms/FunctionAttrs/heap_to_stack.ll b/llvm/test/Transforms/FunctionAttrs/heap_to_stack.ll index 876760a8051..04313cf0e77 100644 --- a/llvm/test/Transforms/FunctionAttrs/heap_to_stack.ll +++ b/llvm/test/Transforms/FunctionAttrs/heap_to_stack.ll @@ -8,7 +8,7 @@ declare void @func_throws(...) declare void @sync_func(i8* %p) -declare void @sync_will_return(i8* %p) willreturn +declare void @sync_will_return(i8* %p) willreturn nounwind declare void @no_sync_func(i8* nocapture %p) nofree nosync willreturn @@ -202,11 +202,11 @@ define i32 @test_lifetime() { } ; TEST 11 -; FIXME: should be ok define void @test11() { %1 = tail call noalias i8* @malloc(i64 4) - ; CHECK: @malloc(i64 4) + ; CHECK: test11 + ; CHECK-NEXT: alloc ; CHECK-NEXT: @sync_will_return(i8* %1) tail call void @sync_will_return(i8* %1) tail call void @free(i8* %1) @@ -330,9 +330,29 @@ define void @test16b(i8 %v, i8** %P) { %1 = tail call noalias i8* @malloc(i64 4) ; CHECK-NEXT: store i8* %1, i8** %P store i8* %1, i8** %P - ; CHECK-NEXT: @no_sync_func(i8* %1) + ; CHECK-NEXT: @no_sync_func(i8* nocapture %1) tail call void @no_sync_func(i8* %1) ; CHECK-NEXT: @free(i8* %1) tail call void @free(i8* %1) ret void } + +define void @test16c(i8 %v, i8** %P) { + ; CHECK: %1 = alloca + %1 = tail call noalias i8* @malloc(i64 4) + ; CHECK-NEXT: store i8* %1, i8** %P + store i8* %1, i8** %P + ; CHECK-NEXT: @no_sync_func(i8* nocapture %1) + tail call void @no_sync_func(i8* %1) nounwind + ; CHECK-NOT: @free + tail call void @free(i8* %1) + ret void +} + +define void @test16d(i8 %v, i8** %P) { + ; CHECK: %1 = tail call noalias i8* @malloc(i64 4) + %1 = tail call noalias i8* @malloc(i64 4) + ; CHECK-NEXT: store i8* %1, i8** %P + store i8* %1, i8** %P + ret void +} diff --git a/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll b/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll index 72de6fb282b..8cb1ec2eb4e 100644 --- a/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll +++ b/llvm/test/Transforms/FunctionAttrs/noalias_returned.ll @@ -204,7 +204,7 @@ define void @test12_1() { ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]]) ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nonnull align 4 dereferenceable(1) [[A]]) ; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]]) -; CHECK-NEXT: tail call void @use_nocapture(i8* noalias [[B]]) +; CHECK-NEXT: tail call void @use_nocapture(i8* noalias nocapture [[B]]) ; CHECK-NEXT: ret void ; %A = alloca i8, align 4 @@ -221,10 +221,10 @@ define void @test12_2(){ ; CHECK-NEXT: [[A:%.*]] = tail call noalias i8* @malloc(i64 4) ; FIXME: This should be @use_nocapture(i8* noalias [[A]]) ; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]]) -; FIXME: This should be @use_nocapture(i8* noalias [[A]]) -; CHECK-NEXT: tail call void @use_nocapture(i8* [[A]]) +; FIXME: This should be @use_nocapture(i8* noalias nocapture [[A]]) +; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]]) ; CHECK-NEXT: tail call void @use(i8* [[A]]) -; CHECK-NEXT: tail call void @use_nocapture(i8* [[A]]) +; CHECK-NEXT: tail call void @use_nocapture(i8* nocapture [[A]]) ; CHECK-NEXT: ret void ; %A = tail call noalias i8* @malloc(i64 4) @@ -239,7 +239,7 @@ declare void @two_args(i8* nocapture , i8* nocapture) define void @test12_3(){ ; CHECK-LABEL: @test12_3( %A = tail call noalias i8* @malloc(i64 4) -; CHECK: tail call void @two_args(i8* nocapture %A, i8* %A) +; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A) tail call void @two_args(i8* %A, i8* %A) ret void } @@ -252,17 +252,17 @@ define void @test12_4(){ %A_1 = getelementptr i8, i8* %A, i64 1 %B_0 = getelementptr i8, i8* %B, i64 0 -; CHECK: tail call void @two_args(i8* noalias %A, i8* noalias %B) +; CHECK: tail call void @two_args(i8* noalias nocapture %A, i8* noalias nocapture %B) tail call void @two_args(i8* %A, i8* %B) -; CHECK: tail call void @two_args(i8* %A, i8* nocapture %A_0) +; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A_0) tail call void @two_args(i8* %A, i8* %A_0) -; CHECK: tail call void @two_args(i8* %A, i8* %A_1) +; CHECK: tail call void @two_args(i8* nocapture %A, i8* nocapture %A_1) tail call void @two_args(i8* %A, i8* %A_1) -; FIXME: This should be @two_args(i8* noalias %A_0, i8* noalias %B_0) -; CHECK: tail call void @two_args(i8* %A_0, i8* nocapture %B_0) +; FIXME: This should be @two_args(i8* noalias nocapture %A_0, i8* noalias nocapture %B_0) +; CHECK: tail call void @two_args(i8* nocapture %A_0, i8* nocapture %B_0) tail call void @two_args(i8* %A_0, i8* %B_0) ret void } |

