[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Nov 4 10:44:01 PST 2002


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.64 -> 1.65

---
Log message:

Instcombine this away:
        %A = getelementptr [4 x int]* %M, long 0, long 0
        %B = getelementptr int* %A, long 2


---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.64 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.65
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.64	Mon Nov  4 10:18:53 2002
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Nov  4 10:43:32 2002
@@ -681,11 +681,17 @@
                    *cast<Constant>(GEP.getOperand(1));
       assert(Indices[0] != 0 && "Constant folding of uint's failed!?");
 
-    } else if (*GEP.idx_begin() == ConstantUInt::getNullValue(Type::LongTy) &&
+    } else if (*GEP.idx_begin() == Constant::getNullValue(Type::LongTy) &&
                Src->getNumOperands() != 1) { 
       // 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());
+    } else if (Src->getOperand(Src->getNumOperands()-1) == 
+               Constant::getNullValue(Type::LongTy)) {
+      // If the src gep ends with a constant array index, merge this get into
+      // it, even if we have a non-zero array index.
+      Indices.insert(Indices.end(), Src->idx_begin(), Src->idx_end()-1);
+      Indices.insert(Indices.end(), GEP.idx_begin(), GEP.idx_end());
     }
 
     if (!Indices.empty())





More information about the llvm-commits mailing list