Bug fix in SetOperandsForMemInstr: handle leading zeros correctly
authorVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 4 Aug 2002 20:51:05 +0000 (20:51 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Sun, 4 Aug 2002 20:51:05 +0000 (20:51 +0000)
when folding or not folding GEPs.

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

lib/Target/SparcV9/SparcV9InstrSelection.cpp

index b9dcd6deb160806f201d8e57bf6d20b1d289d6a3..1b27d32583c645886b1c46475ae6cc1d7ce74178 100644 (file)
@@ -995,18 +995,22 @@ SetOperandsForMemInstr(vector<MachineInstr*>& mvec,
 
   // If we have only constant indices, fold chains of constant indices
   // in this and any preceding GetElemPtr instructions.
+  bool foldedGEPs = false;
   if (allConstantIndices &&
       (ptrChild->getOpLabel() == Instruction::GetElementPtr ||
        ptrChild->getOpLabel() == GetElemPtrIdx))
-    if (Value* newPtr = FoldGetElemChain((InstructionNode*) ptrChild, idxVec))
+    if (Value* newPtr = FoldGetElemChain((InstructionNode*) ptrChild, idxVec)) {
       ptrVal = newPtr;
+      foldedGEPs = true;
+    }
 
   // Append the index vector of the current instruction, if any.
-  // Discard any leading [0] index.
-  if (memInst->getNumIndices() > 0)
+  // Skip the leading [0] index if preceding GEPs were folded into this.
+  if (memInst->getNumIndices() > 0) {
+    assert((!foldedGEPs || IsZero(*memInst->idx_begin())) && "1st index not 0");
     idxVec.insert(idxVec.end(),
-                  memInst->idx_begin() + IsZero(*memInst->idx_begin()),
-                  memInst->idx_end());
+                  memInst->idx_begin() + foldedGEPs, memInst->idx_end());
+  }
 
   // Now create the appropriate operands for the machine instruction
   SetMemOperands_Internal(mvec, mvecI, vmInstrNode,