[llvm-commits] [llvm] r61976 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
sabre at nondot.org
Thu Jan 8 20:53:57 PST 2009
Author: lattner
Date: Thu Jan 8 22:53:57 2009
New Revision: 61976
URL: http://llvm.org/viewvc/llvm-project?rev=61976&view=rev
Log:
move some code, check to see if the input to the GEP is a bitcast
(which is constant time and cheap) before checking hasAllZeroIndices.
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=61976&r1=61975&r2=61976&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Thu Jan 8 22:53:57 2009
@@ -10464,28 +10464,6 @@
}
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 (GEP.hasAllZeroIndices()) {
- if (BitCastInst *BCI = dyn_cast<BitCastInst>(GEP.getOperand(0))) {
- // If the bitcast is of an allocation, and the allocation will be
- // converted to match the type of the cast, don't touch this.
- if (isa<AllocationInst>(BCI->getOperand(0))) {
- // See if the bitcast simplifies, if so, don't nuke this GEP yet.
- if (Instruction *I = visitBitCast(*BCI)) {
- if (I != BCI) {
- I->takeName(BCI);
- BCI->getParent()->getInstList().insert(BCI, I);
- ReplaceInstUsesWith(*BCI, I);
- }
- return &GEP;
- }
- }
- return new BitCastInst(BCI->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.
@@ -10696,7 +10674,28 @@
}
}
}
-
+
+ if (BitCastInst *BCI = dyn_cast<BitCastInst>(PtrOp)) {
+ // If this GEP instruction doesn't move the pointer, just replace the GEP
+ // with a bitcast of the real input to the dest type.
+ if (GEP.hasAllZeroIndices()) {
+ // If the bitcast is of an allocation, and the allocation will be
+ // converted to match the type of the cast, don't touch this.
+ if (isa<AllocationInst>(BCI->getOperand(0))) {
+ // See if the bitcast simplifies, if so, don't nuke this GEP yet.
+ if (Instruction *I = visitBitCast(*BCI)) {
+ if (I != BCI) {
+ I->takeName(BCI);
+ BCI->getParent()->getInstList().insert(BCI, I);
+ ReplaceInstUsesWith(*BCI, I);
+ }
+ return &GEP;
+ }
+ }
+ return new BitCastInst(BCI->getOperand(0), GEP.getType());
+ }
+ }
+
return 0;
}
More information about the llvm-commits
mailing list