[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Mar 5 16:34:01 PST 2003
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.69 -> 1.70
---
Log message:
Implement %test7 in InstCombine/getelementptr.ll
---
Diffs of the changes:
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.69 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.70
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.69 Tue Feb 18 13:57:07 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 5 16:33:14 2003
@@ -807,14 +807,28 @@
std::vector<Value *> Indices;
// Can we combine the two pointer arithmetics offsets?
- if (Src->getNumOperands() == 2 && isa<Constant>(Src->getOperand(1)) &&
- isa<Constant>(GEP.getOperand(1))) {
- // Replace the index list on this GEP with the index on the getelementptr
- Indices.insert(Indices.end(), GEP.idx_begin(), GEP.idx_end());
- Indices[0] = *cast<Constant>(Src->getOperand(1)) +
+ if (Src->getNumOperands() == 2 && isa<Constant>(Src->getOperand(1)) &&
+ isa<Constant>(GEP.getOperand(1))) {
+ // Replace: gep (gep %P, long C1), long C2, ...
+ // With: gep %P, long (C1+C2), ...
+ Value *Sum = *cast<Constant>(Src->getOperand(1)) +
*cast<Constant>(GEP.getOperand(1));
- assert(Indices[0] != 0 && "Constant folding of uint's failed!?");
-
+ assert(Sum && "Constant folding of longs failed!?");
+ GEP.setOperand(0, Src->getOperand(0));
+ GEP.setOperand(1, Sum);
+ AddUsesToWorkList(*Src); // Reduce use count of Src
+ return &GEP;
+ } else if (Src->getNumOperands() == 2 && Src->use_size() == 1) {
+ // Replace: gep (gep %P, long B), long A, ...
+ // With: T = long A+B; gep %P, T, ...
+ //
+ Value *Sum = BinaryOperator::create(Instruction::Add, Src->getOperand(1),
+ GEP.getOperand(1),
+ Src->getName()+".sum", &GEP);
+ GEP.setOperand(0, Src->getOperand(0));
+ GEP.setOperand(1, Sum);
+ WorkList.push_back(cast<Instruction>(Sum));
+ return &GEP;
} 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
More information about the llvm-commits
mailing list