hopefully fix the buildbots: some tests have wrong definitions of malloc and were...
authorNuno Lopes <nunoplopes@sapo.pt>
Thu, 21 Jun 2012 16:47:58 +0000 (16:47 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Thu, 21 Jun 2012 16:47:58 +0000 (16:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158923 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/MemoryBuiltins.cpp
test/Transforms/InstCombine/objsize-64.ll [new file with mode: 0644]

index 2a1afdce329ddfe320e2f7ef34b6b0df5895b345..436cffd6e8ebfdef6da26fe1514b7da01f3104cb 100644 (file)
@@ -419,7 +419,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitCallSite(CallSite CS) {
   if (!Arg)
     return unknown();
 
-  APInt Size = Arg->getValue();
+  APInt Size = Arg->getValue().zextOrSelf(IntTyBits);
   // size determined by just 1 parameter
   if (FnData->SndParam == (unsigned char)-1)
     return std::make_pair(Size, Zero);
@@ -428,7 +428,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitCallSite(CallSite CS) {
   if (!Arg)
     return unknown();
 
-  Size *= Arg->getValue();
+  Size *= Arg->getValue().zextOrSelf(IntTyBits);
   return std::make_pair(Size, Zero);
 
   // TODO: handle more standard functions (+ wchar cousins):
@@ -602,11 +602,13 @@ SizeOffsetEvalType ObjectSizeOffsetEvaluator::visitCallSite(CallSite CS) {
     return unknown();
   }
 
-  Value *FirstArg  = CS.getArgument(FnData->FstParam);
+  Value *FirstArg = CS.getArgument(FnData->FstParam);
+  FirstArg = Builder.CreateZExt(FirstArg, IntTy);
   if (FnData->SndParam == (unsigned char)-1)
     return std::make_pair(FirstArg, Zero);
 
   Value *SecondArg = CS.getArgument(FnData->SndParam);
+  SecondArg = Builder.CreateZExt(SecondArg, IntTy);
   Value *Size = Builder.CreateMul(FirstArg, SecondArg);
   return std::make_pair(Size, Zero);
 
diff --git a/test/Transforms/InstCombine/objsize-64.ll b/test/Transforms/InstCombine/objsize-64.ll
new file mode 100644 (file)
index 0000000..d903f1e
--- /dev/null
@@ -0,0 +1,13 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+declare noalias i8* @malloc(i32) nounwind
+declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readonly
+
+; CHECK: @f1
+define i64 @f1() {
+  %call = call i8* @malloc(i32 4)
+  %size = call i64 @llvm.objectsize.i64(i8* %call, i1 false)
+; CHECK-NEXT: ret i64 4
+  ret i64 %size
+}