[llvm-branch-commits] [llvm-branch] r96828 - in /llvm/branches/Apple/Hermes: lib/Transforms/IPO/FunctionAttrs.cpp lib/Transforms/InstCombine/InstCombineCalls.cpp test/Transforms/InstCombine/objsize.ll

Evan Cheng evan.cheng at apple.com
Mon Feb 22 15:39:21 PST 2010


Author: evancheng
Date: Mon Feb 22 17:39:21 2010
New Revision: 96828

URL: http://llvm.org/viewvc/llvm-project?rev=96828&view=rev
Log:
Merge 96825.

Modified:
    llvm/branches/Apple/Hermes/lib/Transforms/IPO/FunctionAttrs.cpp   (props changed)
    llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll

Propchange: llvm/branches/Apple/Hermes/lib/Transforms/IPO/FunctionAttrs.cpp
------------------------------------------------------------------------------
    (empty)

Modified: llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=96828&r1=96827&r2=96828&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon Feb 22 17:39:21 2010
@@ -319,7 +319,7 @@
     if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op1)) {
       if (GV->hasDefinitiveInitializer()) {
         Constant *C = GV->getInitializer();
-        size_t globalSize = TD->getTypeAllocSize(C->getType());
+        uint64_t globalSize = TD->getTypeAllocSize(C->getType());
         return ReplaceInstUsesWith(CI, ConstantInt::get(ReturnTy, globalSize));
       } else {
         Constant *RetVal = ConstantInt::get(ReturnTy, Min ? 0 : -1ULL);
@@ -341,16 +341,21 @@
       // Get what we're pointing to and its size. 
       const PointerType *BaseType = 
         cast<PointerType>(Operand->getType());
-      size_t Size = TD->getTypeAllocSize(BaseType->getElementType());
+      uint64_t Size = TD->getTypeAllocSize(BaseType->getElementType());
       
       // Get the current byte offset into the thing. Use the original
       // operand in case we're looking through a bitcast.
       SmallVector<Value*, 8> Ops(CE->op_begin()+1, CE->op_end());
       const PointerType *OffsetType =
         cast<PointerType>(GEP->getPointerOperand()->getType());
-      size_t Offset = TD->getIndexedOffset(OffsetType, &Ops[0], Ops.size());
+      uint64_t Offset = TD->getIndexedOffset(OffsetType, &Ops[0], Ops.size());
 
-      assert(Size >= Offset);
+      if (Size < Offset) {
+        // Out of bound reference? Negative index normalized to large
+        // index? Just return "I don't know".
+        Constant *RetVal = ConstantInt::get(ReturnTy, Min ? 0 : -1ULL);
+        return ReplaceInstUsesWith(CI, RetVal);
+      }
       
       Constant *RetVal = ConstantInt::get(ReturnTy, Size-Offset);
       return ReplaceInstUsesWith(CI, RetVal);

Modified: llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll?rev=96828&r1=96827&r2=96828&view=diff
==============================================================================
--- llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll Mon Feb 22 17:39:21 2010
@@ -72,4 +72,34 @@
   ret i32 %1
 }
 
-declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
\ No newline at end of file
+; rdar://7674946
+ at array = internal global [480 x float] zeroinitializer ; <[480 x float]*> [#uses=1]
+
+declare i8* @__memcpy_chk(i8*, i8*, i32, i32) nounwind
+
+declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
+
+declare i8* @__inline_memcpy_chk(i8*, i8*, i32) nounwind inlinehint
+
+define void @test3() nounwind {
+; CHECK: @test3
+entry:
+  br i1 undef, label %bb11, label %bb12
+
+bb11:
+  %0 = getelementptr inbounds float* getelementptr inbounds ([480 x float]* @array, i32 0, i32 128), i32 -127 ; <float*> [#uses=1]
+  %1 = bitcast float* %0 to i8*                   ; <i8*> [#uses=1]
+  %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false) ; <i32> [#uses=1]
+  %3 = call i8* @__memcpy_chk(i8* undef, i8* undef, i32 512, i32 %2) nounwind ; <i8*> [#uses=0]
+; CHECK: @__memcpy_chk
+  unreachable
+
+bb12:
+  %4 = getelementptr inbounds float* getelementptr inbounds ([480 x float]* @array, i32 0, i32 128), i32 -127 ; <float*> [#uses=1]
+  %5 = bitcast float* %4 to i8*                   ; <i8*> [#uses=1]
+  %6 = call i8* @__inline_memcpy_chk(i8* %5, i8* undef, i32 512) nounwind inlinehint ; <i8*> [#uses=0]
+; CHECK: @__inline_memcpy_chk
+  unreachable
+}
+
+declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly





More information about the llvm-branch-commits mailing list