[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
sabre at nondot.org
Sun Mar 25 13:43:30 PDT 2007
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.689 -> 1.690
---
Log message:
implement Transforms/InstCombine/cast2.ll:test3 and PR1263: http://llvm.org/PR1263
---
Diffs of the changes: (+21 -1)
InstructionCombining.cpp | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletion(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.690
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689 Sun Mar 25 14:55:33 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Mar 25 15:43:09 2007
@@ -7896,10 +7896,22 @@
if (GEP.getNumOperands() == 2 && HasZeroPointerIndex)
return ReplaceInstUsesWith(GEP, PtrOp);
+ // Keep track of whether all indices are zero constants integers.
+ bool AllZeroIndices = true;
+
// Eliminate unneeded casts for indices.
bool MadeChange = false;
+
gep_type_iterator GTI = gep_type_begin(GEP);
- for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI)
+ for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI) {
+ // Track whether this GEP has all zero indices, if so, it doesn't move the
+ // input pointer, it just changes its type.
+ if (AllZeroIndices) {
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP.getOperand(i)))
+ AllZeroIndices = CI->isNullValue();
+ else
+ AllZeroIndices = false;
+ }
if (isa<SequentialType>(*GTI)) {
if (CastInst *CI = dyn_cast<CastInst>(GEP.getOperand(i))) {
if (CI->getOpcode() == Instruction::ZExt ||
@@ -7929,8 +7941,16 @@
MadeChange = true;
}
}
+ }
if (MadeChange) return &GEP;
+ // If this GEP instruction doesn't move the pointer, and if the input operand
+ // is a bitcast of another pointer, just replace the GEP with a bitcast of the
+ // real input to the dest type.
+ if (AllZeroIndices && isa<BitCastInst>(GEP.getOperand(0)))
+ return new BitCastInst(cast<BitCastInst>(GEP.getOperand(0))->getOperand(0),
+ GEP.getType());
+
// Combine Indices - If the source pointer to this getelementptr instruction
// is a getelementptr instruction, combine the indices of the two
// getelementptr instructions into a single instruction.
More information about the llvm-commits
mailing list