From 5840779cc990ffb81045ebfb4f5ef6d1d90ee3a6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 9 Jan 2009 04:53:57 +0000 Subject: [PATCH] move some code, check to see if the input to the GEP is a bitcast (which is constant time and cheap) before checking hasAllZeroIndices. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61976 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 83158276e2c..699f2e01ad8 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -10464,28 +10464,6 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } 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(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(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 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } } } - + + if (BitCastInst *BCI = dyn_cast(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(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; }