summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-01-19 23:07:10 +0000
committerSanjay Patel <spatel@rotateright.com>2016-01-19 23:07:10 +0000
commit582857c95c88f473c7e897aa4dd0e3ef315b867b (patch)
tree49e9ad5feeb1dd3cf73b4e53c6d5464fd466c9f6
parentc4672087915503a77872669b086b487ebda430af (diff)
downloadbcm5719-llvm-582857c95c88f473c7e897aa4dd0e3ef315b867b.tar.gz
bcm5719-llvm-582857c95c88f473c7e897aa4dd0e3ef315b867b.zip
add tests to show missing memset/malloc optimizations (PR25892)
llvm-svn: 258218
-rw-r--r--llvm/test/Transforms/InstCombine/memset-1.ll37
-rw-r--r--llvm/test/Transforms/InstCombine/memset_chk-1.ll38
2 files changed, 75 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/memset-1.ll b/llvm/test/Transforms/InstCombine/memset-1.ll
index 991567d6b59..8e20a2c7bbb 100644
--- a/llvm/test/Transforms/InstCombine/memset-1.ll
+++ b/llvm/test/Transforms/InstCombine/memset-1.ll
@@ -15,3 +15,40 @@ define i8* @test_simplify1(i8* %mem, i32 %val, i32 %size) {
ret i8* %ret
; CHECK: ret i8* %mem
}
+
+; FIXME: memset(malloc(x), 0, x) -> calloc(1, x)
+
+define float* @pr25892(i32 %size) #0 {
+entry:
+ %call = tail call i8* @malloc(i32 %size) #1
+ %cmp = icmp eq i8* %call, null
+ br i1 %cmp, label %cleanup, label %if.end
+if.end:
+ %bc = bitcast i8* %call to float*
+ %call2 = tail call i8* @memset(i8* nonnull %call, i32 0, i32 %size) #1
+ br label %cleanup
+cleanup:
+ %retval.0 = phi float* [ %bc, %if.end ], [ null, %entry ]
+ ret float* %retval.0
+
+; CHECK-LABEL: @pr25892(
+; CHECK: entry:
+; CHECK-NEXT: %call = tail call i8* @malloc(i32 %size) #1
+; CHECK-NEXT: %cmp = icmp eq i8* %call, null
+; CHECK-NEXT: br i1 %cmp, label %cleanup, label %if.end
+; CHECK: if.end:
+; CHECK-NEXT: %bc = bitcast i8* %call to float*
+; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* nonnull %call, i8 0, i32 %size, i32 1, i1 false)
+; CHECK-NEXT: br label %cleanup
+; CHECK: cleanup:
+; CHECK-NEXT: %retval.0 = phi float* [ %bc, %if.end ], [ null, %entry ]
+; CHECK-NEXT: ret float* %retval.0
+}
+
+declare noalias i8* @malloc(i32) #1
+declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2
+
+attributes #0 = { nounwind ssp uwtable }
+attributes #1 = { nounwind }
+attributes #2 = { nounwind readnone }
+
diff --git a/llvm/test/Transforms/InstCombine/memset_chk-1.ll b/llvm/test/Transforms/InstCombine/memset_chk-1.ll
index 56ea14c8292..9d08e96cb49 100644
--- a/llvm/test/Transforms/InstCombine/memset_chk-1.ll
+++ b/llvm/test/Transforms/InstCombine/memset_chk-1.ll
@@ -90,3 +90,41 @@ declare i64 @strlen(i8* nocapture)
declare i64 @llvm.objectsize.i64.p0i8(i8*, i1)
declare i8* @__memset_chk(i8*, i32, i64, i64)
+
+; FIXME: memset(malloc(x), 0, x) -> calloc(1, x)
+
+define float* @pr25892(i64 %size) #0 {
+entry:
+ %call = tail call i8* @malloc(i64 %size) #1
+ %cmp = icmp eq i8* %call, null
+ br i1 %cmp, label %cleanup, label %if.end
+if.end:
+ %bc = bitcast i8* %call to float*
+ %call2 = tail call i64 @llvm.objectsize.i64.p0i8(i8* nonnull %call, i1 false)
+ %call3 = tail call i8* @__memset_chk(i8* nonnull %call, i32 0, i64 %size, i64 %call2) #1
+ br label %cleanup
+cleanup:
+ %retval.0 = phi float* [ %bc, %if.end ], [ null, %entry ]
+ ret float* %retval.0
+
+; CHECK-LABEL: @pr25892(
+; CHECK: entry:
+; CHECK-NEXT: %call = tail call i8* @malloc(i64 %size)
+; CHECK-NEXT: %cmp = icmp eq i8* %call, null
+; CHECK-NEXT: br i1 %cmp, label %cleanup, label %if.end
+; CHECK: if.end:
+; CHECK-NEXT: %bc = bitcast i8* %call to float*
+; CHECK-NEXT: %call2 = tail call i64 @llvm.objectsize.i64.p0i8(i8* nonnull %call, i1 false)
+; CHECK-NEXT: %call3 = tail call i8* @__memset_chk(i8* nonnull %call, i32 0, i64 %size, i64 %call2)
+; CHECK-NEXT: br label %cleanup
+; CHECK: cleanup:
+; CHECK-NEXT: %retval.0 = phi float* [ %bc, %if.end ], [ null, %entry ]
+; CHECK-NEXT: ret float* %retval.0
+}
+
+declare noalias i8* @malloc(i64) #1
+
+attributes #0 = { nounwind ssp uwtable }
+attributes #1 = { nounwind }
+attributes #2 = { nounwind readnone }
+
OpenPOWER on IntegriCloud