From 12c807873a5988d900c8032e7d98f8f07da5c628 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Fri, 11 May 2012 18:25:29 +0000 Subject: objectsize: add a few more tests and fix a bug git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156625 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/objsize.ll | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test/Transforms/InstCombine/objsize.ll') diff --git a/test/Transforms/InstCombine/objsize.ll b/test/Transforms/InstCombine/objsize.ll index 1e62a93548..e33385e6cc 100644 --- a/test/Transforms/InstCombine/objsize.ll +++ b/test/Transforms/InstCombine/objsize.ll @@ -185,6 +185,61 @@ define i32 @test9(i32 %x, i32 %y) nounwind { ; CHECK-NEXT: select i1 {{.*}}, i32 0, } +; CHECK: @test10 +define i32 @test10(i32 %x, i32 %y) nounwind { + %alloc = call noalias i8* @calloc(i32 %x, i32 %y) nounwind + %gep = getelementptr inbounds i8* %alloc, i32 5 + %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false, i32 2) + ret i32 %objsize +; CHECK-NEXT: mul i32 +; CHECK-NEXT: add i32 {{.*}}, -5 +; CHECK-NEXT: icmp ult i32 {{.*}}, 5 +; CHECK-NEXT: select i1 +; CHECK-NEXT: ret +} + +; CHECK: @test11 +define i32 @test11(i32 %x, i32 %y) nounwind { + %alloc = call i8* @malloc(i32 %x) + %allocd = bitcast i8* %alloc to double* + %gep = getelementptr double* %allocd, i32 %y + %gepi8 = bitcast double* %gep to i8* + %objsize = call i32 @llvm.objectsize.i32(i8* %gepi8, i1 false, i32 2) + ret i32 %objsize +; CHECK-NEXT: shl i32 +; CHECK-NEXT: sub i32 +; CHECK-NEXT: icmp ugt i32 +; CHECK-NEXT: select i1 +; CHECK-NEXT: ret +} + +; CHECK: @test12 +define i32 @test12(i32 %x) nounwind { + %alloc = alloca i32, i32 %x, align 16 + %gep = getelementptr i32* %alloc, i32 7 + %gepi8 = bitcast i32* %gep to i8* + %objsize = call i32 @llvm.objectsize.i32(i8* %gepi8, i1 false, i32 2) + ret i32 %objsize +; CHECK-NEXT: shl i32 +; CHECK-NEXT: add i32 {{.*}}, -28 +; CHECK-NEXT: icmp ult i32 {{.*}}, 28 +; CHECK-NEXT: select i1 +; CHECK-NEXT: ret +} + +; CHECK: @test13 +define i32 @test13(i32 %x, i32 %y) nounwind { + %alloc = call i8* @calloc(i32 %x, i32 %y) + %alloc2 = call i8* @malloc(i32 %x) + %objsize = call i32 @llvm.objectsize.i32(i8* %alloc, i1 false, i32 1) + %objsize2 = call i32 @llvm.objectsize.i32(i8* %alloc2, i1 false, i32 1) + %add = add i32 %objsize, %objsize2 + ret i32 %add +; CHECK: objectsize +; CHECK: objectsize +; CHECK: add +} + ; CHECK: @overflow define i32 @overflow() { %alloc = call noalias i8* @malloc(i32 21) nounwind -- cgit v1.2.3