diff options
author | Duncan Sands <baldrick@free.fr> | 2010-05-27 19:09:06 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2010-05-27 19:09:06 +0000 |
commit | 1d9b973fd7e60e4149678a03aac762551c846f13 (patch) | |
tree | e002a3d6cf5b6a3049d504b189c0052caa5049e6 /test | |
parent | 084fb0ea3246300aa81dd2561ce4d84401b74792 (diff) | |
download | external_llvm-1d9b973fd7e60e4149678a03aac762551c846f13.zip external_llvm-1d9b973fd7e60e4149678a03aac762551c846f13.tar.gz external_llvm-1d9b973fd7e60e4149678a03aac762551c846f13.tar.bz2 |
Teach instCombine to remove malloc+free if malloc's only uses are comparisons
to null. Patch by Matti Niemenmaa.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104871 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/Transforms/InstCombine/badmalloc.ll | 1 | ||||
-rw-r--r-- | test/Transforms/InstCombine/malloc-free-delete.ll | 20 |
2 files changed, 17 insertions, 4 deletions
diff --git a/test/Transforms/InstCombine/badmalloc.ll b/test/Transforms/InstCombine/badmalloc.ll index cab23b5..f5a623d 100644 --- a/test/Transforms/InstCombine/badmalloc.ll +++ b/test/Transforms/InstCombine/badmalloc.ll @@ -10,6 +10,7 @@ declare void @free(i8*) define i1 @test1() { %A = call noalias i8* @malloc(i64 4) nounwind %B = icmp eq i8* %A, null + store i8 0, i8* %A call void @free(i8* %A) ret i1 %B diff --git a/test/Transforms/InstCombine/malloc-free-delete.ll b/test/Transforms/InstCombine/malloc-free-delete.ll index a4b7496..317786f 100644 --- a/test/Transforms/InstCombine/malloc-free-delete.ll +++ b/test/Transforms/InstCombine/malloc-free-delete.ll @@ -1,13 +1,25 @@ -; RUN: opt < %s -instcombine -globaldce -S | FileCheck %s +; RUN: opt < %s -instcombine -S | FileCheck %s ; PR1201 define i32 @main(i32 %argc, i8** %argv) { - %c_19 = alloca i8* ; <i8**> [#uses=2] - %malloc_206 = malloc i8, i32 10 ; <i8*> [#uses=1] + %c_19 = alloca i8* + %malloc_206 = malloc i8, i32 10 ; CHECK-NOT: malloc store i8* %malloc_206, i8** %c_19 - %tmp_207 = load i8** %c_19 ; <i8*> [#uses=1] + %tmp_207 = load i8** %c_19 free i8* %tmp_207 ; CHECK-NOT: free ret i32 0 ; CHECK: ret i32 0 } + +declare i8* @malloc(i32) +declare void @free(i8*) + +define i1 @foo() { +; CHECK: @foo +; CHECK-NEXT: ret i1 false + %m = call i8* @malloc(i32 1) + %z = icmp eq i8* %m, null + call void @free(i8* %m) + ret i1 %z +} |