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

Eric Christopher echristo at apple.com
Mon Feb 15 12:37:52 PST 2010


Author: echristo
Date: Mon Feb 15 14:37:52 2010
New Revision: 96260

URL: http://llvm.org/viewvc/llvm-project?rev=96260&view=rev
Log:
Merge from mainline:

r96134 | echristo | 2010-02-13 15:38:01 -0800 (Sat, 13 Feb 2010) | 4 lines

Fix a problem where we had bitcasted operands that gave us
odd offsets since the bitcasted pointer size and the offset pointer
size are going to be different types for the GEP vs base object.


Modified:
    llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll

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=96260&r1=96259&r2=96260&view=diff

==============================================================================
--- llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/branches/Apple/Hermes/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon Feb 15 14:37:52 2010
@@ -334,17 +334,21 @@
       // Make sure we're not a constant offset from an external
       // global.
       Value *Operand = GEP->getPointerOperand();
+      Operand = Operand->stripPointerCasts();
       if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand))
         if (!GV->hasDefinitiveInitializer()) break;
       
-      // Get what we're pointing to and its size.
-      const PointerType *PT = 
+      // Get what we're pointing to and its size. 
+      const PointerType *BaseType = 
         cast<PointerType>(Operand->getType());
-      size_t Size = TD->getTypeAllocSize(PT->getElementType());
+      size_t Size = TD->getTypeAllocSize(BaseType->getElementType());
       
-      // Get the current byte offset into the thing.
+      // 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());
-      size_t Offset = TD->getIndexedOffset(PT, &Ops[0], Ops.size());
+      const PointerType *OffsetType =
+        cast<PointerType>(GEP->getPointerOperand()->getType());
+      size_t Offset = TD->getIndexedOffset(OffsetType, &Ops[0], Ops.size());
 
       assert(Size >= Offset);
       

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=96260&r1=96259&r2=96260&view=diff

==============================================================================
--- llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/branches/Apple/Hermes/test/Transforms/InstCombine/objsize.ll Mon Feb 15 14:37:52 2010
@@ -63,4 +63,13 @@
   unreachable
 }
 
+ at .str5 = private constant [9 x i32] [i32 97, i32 98, i32 99, i32 100, i32 0, i32
+ 101, i32 102, i32 103, i32 0], align 4 ;
+define i32 @test2() nounwind {
+; CHECK: @test2
+; CHECK-NEXT: ret i32 34
+  %1 = call i32 @llvm.objectsize.i32(i8* getelementptr (i8* bitcast ([9 x i32]* @.str5 to i8*), i32 2), i1 false)
+  ret i32 %1
+}
+
 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
\ No newline at end of file





More information about the llvm-branch-commits mailing list