objectsize: add support for GEPs with non-constant indexes
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineAddSub.cpp
index 6a39fc33d488be4113d0c9261c682d547473193c..8420a6a96e47d92a345b2d34a2b345c79a426b6d 100644 (file)
@@ -423,7 +423,8 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
 /// EmitGEPOffset - Given a getelementptr instruction/constantexpr, emit the
 /// code necessary to compute the offset from the base pointer (without adding
 /// in the base pointer).  Return the result as a signed integer of intptr size.
-Value *InstCombiner::EmitGEPOffset(User *GEP) {
+/// If NoNUW is true, then the NUW flag is not used.
+Value *InstCombiner::EmitGEPOffset(User *GEP, bool NoNUW) {
   TargetData &TD = *getTargetData();
   gep_type_iterator GTI = gep_type_begin(GEP);
   Type *IntPtrTy = TD.getIntPtrType(GEP->getContext());
@@ -431,7 +432,7 @@ Value *InstCombiner::EmitGEPOffset(User *GEP) {
 
   // If the GEP is inbounds, we know that none of the addressing operations will
   // overflow in an unsigned sense.
-  bool isInBounds = cast<GEPOperator>(GEP)->isInBounds();
+  bool isInBounds = cast<GEPOperator>(GEP)->isInBounds() && !NoNUW;
   
   // Build a mask for high order bits.
   unsigned IntPtrWidth = TD.getPointerSizeInBits();