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

Eric Christopher echristo at apple.com
Thu Feb 11 09:44:04 PST 2010


Author: echristo
Date: Thu Feb 11 11:44:04 2010
New Revision: 95877

URL: http://llvm.org/viewvc/llvm-project?rev=95877&view=rev
Log:
Make sure that ConstantExpr offsets also aren't off of extern
symbols.

Thanks to Duncan Sands for the testcase!

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=95877&r1=95876&r2=95877&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Feb 11 11:44:04 2010
@@ -331,9 +331,15 @@
       if (CE->getOpcode() != Instruction::GetElementPtr) break;
       GEPOperator *GEP = cast<GEPOperator>(CE);
       
+      // Make sure we're not a constant offset from an external
+      // global.
+      Value *Operand = GEP->getPointerOperand();
+      if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Operand))
+        if (!GV->hasDefinitiveInitializer()) break;
+      
       // Get what we're pointing to and its size.
       const PointerType *PT = 
-        cast<PointerType>(GEP->getPointerOperand()->getType());
+        cast<PointerType>(Operand->getType());
       size_t Size = TD->getTypeAllocSize(PT->getElementType());
       
       // Get the current byte offset into the thing.
@@ -345,7 +351,7 @@
       Constant *RetVal = ConstantInt::get(ReturnTy, Size-Offset);
       return ReplaceInstUsesWith(CI, RetVal);
       
-    } 
+    }
   }
   case Intrinsic::bswap:
     // bswap(bswap(x)) -> x

Modified: llvm/trunk/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/objsize.ll?rev=95877&r1=95876&r2=95877&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/objsize.ll Thu Feb 11 11:44:04 2010
@@ -48,4 +48,19 @@
   ret i1 %2
 }
 
+define void @test1(i8* %q, i32 %x) nounwind noinline {
+; CHECK: @test1
+; CHECK: objectsize.i32
+entry:
+  %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 10), i1 false) ; <i64> [#uses=1]
+  %1 = icmp eq i32 %0, -1                         ; <i1> [#uses=1]
+  br i1 %1, label %"47", label %"46"
+
+"46":                                             ; preds = %entry
+  unreachable
+
+"47":                                             ; preds = %entry
+  unreachable
+}
+
 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
\ No newline at end of file





More information about the llvm-commits mailing list