[llvm-commits] [llvm] r156625 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCalls.cpp test/Transforms/InstCombine/objsize.ll

Nuno Lopes nunoplopes at sapo.pt
Fri May 11 11:25:29 PDT 2012


Author: nlopes
Date: Fri May 11 13:25:29 2012
New Revision: 156625

URL: http://llvm.org/viewvc/llvm-project?rev=156625&view=rev
Log:
objectsize: add a few more tests and fix a bug

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/trunk/test/Transforms/InstCombine/objsize.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=156625&r1=156624&r2=156625&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Fri May 11 13:25:29 2012
@@ -208,7 +208,7 @@
       Size = CI->getZExtValue();
       return 1;
     }
-    return 0;
+    return Penalty >= 2 ? 0 : 2;
 
   } else if (CallInst *MI = extractCallocCall(Alloc)) {
     Value *Arg1 = MI->getArgOperand(0);

Modified: llvm/trunk/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/objsize.ll?rev=156625&r1=156624&r2=156625&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/objsize.ll Fri May 11 13:25:29 2012
@@ -185,6 +185,61 @@
 ; 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





More information about the llvm-commits mailing list