[llvm] r173998 - stripAndComputeConstantOffsets is only called on pointers; check this

Dan Gohman dan433584 at gmail.com
Wed Jan 30 16:12:20 PST 2013


Author: djg
Date: Wed Jan 30 18:12:20 2013
New Revision: 173998

URL: http://llvm.org/viewvc/llvm-project?rev=173998&view=rev
Log:
stripAndComputeConstantOffsets is only called on pointers; check this
with an assert instead of failing and requiring callers to check for failure.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=173998&r1=173997&r2=173998&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Jan 30 18:12:20 2013
@@ -665,8 +665,7 @@ Value *llvm::SimplifyAddInst(Value *Op0,
 /// no constant offsets applied.
 static Constant *stripAndComputeConstantOffsets(const DataLayout &TD,
                                                 Value *&V) {
-  if (!V->getType()->isPointerTy())
-    return 0;
+  assert(V->getType()->isPointerTy());
 
   unsigned IntPtrWidth = TD.getPointerSizeInBits();
   APInt Offset = APInt::getNullValue(IntPtrWidth);
@@ -701,11 +700,7 @@ static Constant *stripAndComputeConstant
 static Constant *computePointerDifference(const DataLayout &TD,
                                           Value *LHS, Value *RHS) {
   Constant *LHSOffset = stripAndComputeConstantOffsets(TD, LHS);
-  if (!LHSOffset)
-    return 0;
   Constant *RHSOffset = stripAndComputeConstantOffsets(TD, RHS);
-  if (!RHSOffset)
-    return 0;
 
   // If LHS and RHS are not related via constant offsets to the same base
   // value, there is nothing we can do here.
@@ -1710,11 +1705,7 @@ static Constant *computePointerICmp(cons
   }
 
   Constant *LHSOffset = stripAndComputeConstantOffsets(TD, LHS);
-  if (!LHSOffset)
-    return 0;
   Constant *RHSOffset = stripAndComputeConstantOffsets(TD, RHS);
-  if (!RHSOffset)
-    return 0;
 
   // If LHS and RHS are not related via constant offsets to the same base
   // value, there is nothing we can do here.





More information about the llvm-commits mailing list