From 865ae1a9e77920e07c4a6a992736109c2cd4fe02 Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Thu, 6 Jan 2011 02:44:52 +0000 Subject: [PATCH] Move the GEP handling in CodeGenPrepare to OptimizeInst(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122944 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/CodeGenPrepare.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 4f14a479eb4..166d9d6ee3f 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -1003,6 +1003,17 @@ bool CodeGenPrepare::OptimizeInst(Instruction *I) { MadeChange |= OptimizeMemoryInst(I, SI->getOperand(1), SI->getOperand(0)->getType(), SunkAddrs); + } else if (GetElementPtrInst *GEPI = dyn_cast(I)) { + if (GEPI->hasAllZeroIndices()) { + /// The GEP operand must be a pointer, so must its result -> BitCast + Instruction *NC = new BitCastInst(GEPI->getOperand(0), GEPI->getType(), + GEPI->getName(), GEPI); + GEPI->replaceAllUsesWith(NC); + GEPI->eraseFromParent(); + ++NumGEPsElim; + MadeChange = true; + OptimizeInst(NC); + } } return MadeChange; @@ -1031,18 +1042,7 @@ bool CodeGenPrepare::OptimizeBlock(BasicBlock &BB) { for (BasicBlock::iterator BBI = BB.begin(), E = BB.end(); BBI != E; ) { Instruction *I = BBI++; - if (GetElementPtrInst *GEPI = dyn_cast(I)) { - if (GEPI->hasAllZeroIndices()) { - /// The GEP operand must be a pointer, so must its result -> BitCast - Instruction *NC = new BitCastInst(GEPI->getOperand(0), GEPI->getType(), - GEPI->getName(), GEPI); - GEPI->replaceAllUsesWith(NC); - GEPI->eraseFromParent(); - ++NumGEPsElim; - MadeChange = true; - BBI = NC; - } - } else if (CallInst *CI = dyn_cast(I)) { + if (CallInst *CI = dyn_cast(I)) { // If we found an inline asm expession, and if the target knows how to // lower it to normal LLVM code, do so now. if (TLI && isa(CI->getCalledValue())) {