- Change getelementptr instruction to use long indexes instead of uint
authorChris Lattner <sabre@nondot.org>
Wed, 11 Sep 2002 01:21:33 +0000 (01:21 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 11 Sep 2002 01:21:33 +0000 (01:21 +0000)
    indexes for sequential types.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3682 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetData.cpp
lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
lib/Transforms/Scalar/InstructionCombining.cpp

index 7c55f6730ed2d9da351ca03999552ad27d4e0b7d..761ae00ae373ea5e7ac2fe4eb215d69fce1b4554 100644 (file)
@@ -157,17 +157,17 @@ uint64_t TargetData::getIndexedOffset(const Type *ptrTy,
   assert(isa<PointerType>(Ty) && "Illegal argument for getIndexedOffset()");
   uint64_t Result = 0;
 
-  for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) {
-    if (Idx[CurIDX]->getType() == Type::UIntTy) {
+  for (unsigned CurIDX = 0; CurIDX != Idx.size(); ++CurIDX) {
+    if (Idx[CurIDX]->getType() == Type::LongTy) {
       // Update Ty to refer to current element
       Ty = cast<SequentialType>(Ty)->getElementType();
 
       // Get the array index and the size of each array element.
       // Both must be known constants, or this will fail.
       // Also, the product needs to be sign-extended from 32 to 64 bits.
-      uint64_t elementSize = this->getTypeSize(Ty);
-      uint64_t arrayIdx = cast<ConstantUInt>(Idx[CurIDX])->getValue();
-      Result += (uint64_t) (int) (arrayIdx * elementSize); // sign-extend
+      int64_t elementSize = (int64_t)getTypeSize(Ty);
+      int64_t arrayIdx = cast<ConstantSInt>(Idx[CurIDX])->getValue();
+      Result += (uint64_t)(arrayIdx * elementSize);
 
     } else if (const StructType *STy = dyn_cast<const StructType>(Ty)) {
       assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
index a6d7e37cdb6f34235480d70ee9aab35059cbe797..7a2ad4b03e11188fd05ea16e4c7383f9e67f6ba6 100644 (file)
@@ -94,7 +94,7 @@ DecomposePass::decomposeArrayRef(GetElementPtrInst &GEP)
         continue;
     } else {
       // Not the first index: include initial [0] to deref the last ptr
-      Indices.push_back(Constant::getNullValue(Type::UIntTy));
+      Indices.push_back(Constant::getNullValue(Type::LongTy));
     }
 
     Indices.push_back(*OI);
@@ -110,7 +110,7 @@ DecomposePass::decomposeArrayRef(GetElementPtrInst &GEP)
 
   // Get the final index vector, including an initial [0] as before.
   std::vector<Value*> Indices;
-  Indices.push_back(Constant::getNullValue(Type::UIntTy));
+  Indices.push_back(Constant::getNullValue(Type::LongTy));
   Indices.push_back(*OI);
 
   Value *NewVal = new GetElementPtrInst(LastPtr, Indices, GEP.getName(),
index 9c1076e448148f2d3d072bfbb0857ea5c427dd85..179f3b296ab080650b3f8584a6335f572ad8b296 100644 (file)
@@ -649,7 +649,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
   // Is it 'getelementptr %P, uint 0'  or 'getelementptr %P'
   // If so, eliminate the noop.
   if ((GEP.getNumOperands() == 2 &&
-       GEP.getOperand(1) == Constant::getNullValue(Type::UIntTy)) ||
+       GEP.getOperand(1) == Constant::getNullValue(Type::LongTy)) ||
       GEP.getNumOperands() == 1)
     return ReplaceInstUsesWith(GEP, GEP.getOperand(0));
 
@@ -669,7 +669,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
                    *cast<Constant>(GEP.getOperand(1));
       assert(Indices[0] != 0 && "Constant folding of uint's failed!?");
 
-    } else if (*GEP.idx_begin() == ConstantUInt::get(Type::UIntTy, 0)) { 
+    } else if (*GEP.idx_begin() == ConstantUInt::getNullValue(Type::LongTy)) { 
       // Otherwise we can do the fold if the first index of the GEP is a zero
       Indices.insert(Indices.end(), Src->idx_begin(), Src->idx_end());
       Indices.insert(Indices.end(), GEP.idx_begin()+1, GEP.idx_end());