From: Nick Lewycky Date: Sun, 12 Feb 2012 00:47:24 +0000 (+0000) Subject: Don't traverse the PHI nodes twice. No functionality change! X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=8e4ba6b954d58bd60b342770dfca62de4cf4eb6e;p=oota-llvm.git Don't traverse the PHI nodes twice. No functionality change! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150319 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 9d7477a9ac3..b7a5b51c736 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2294,7 +2294,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, /// EvaluateBlock - Evaluate all instructions in block BB, returning true if /// successful, false if we can't evaluate it. NewBB returns the next BB that /// control flows into, or null upon return. -static bool EvaluateBlock(BasicBlock *BB, BasicBlock *&NextBB, +static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB, std::vector &CallStack, DenseMap &Values, DenseMap &MutatedMemory, @@ -2302,9 +2302,6 @@ static bool EvaluateBlock(BasicBlock *BB, BasicBlock *&NextBB, SmallPtrSet &SimpleConstants, const TargetData *TD, const TargetLibraryInfo *TLI) { - // CurInst - The current instruction we're evaluating. - BasicBlock::iterator CurInst = BB->getFirstNonPHI(); - // This is the main evaluation loop. while (1) { Constant *InstResult = 0; @@ -2538,9 +2535,11 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, // CurBB - The current basic block we're evaluating. BasicBlock *CurBB = F->begin(); + BasicBlock::iterator CurInst = CurBB->begin(); + while (1) { BasicBlock *NextBB; - if (!EvaluateBlock(CurBB, NextBB, CallStack, Values, MutatedMemory, + if (!EvaluateBlock(CurInst, NextBB, CallStack, Values, MutatedMemory, AllocaTmps, SimpleConstants, TD, TLI)) return false; @@ -2564,8 +2563,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, // are any PHI nodes. If so, evaluate them with information about where // we came from. PHINode *PN = 0; - for (BasicBlock::iterator Inst = NextBB->begin(); - (PN = dyn_cast(Inst)); ++Inst) + for (CurInst = NextBB->begin(); + (PN = dyn_cast(CurInst)); ++CurInst) Values[PN] = getVal(Values, PN->getIncomingValueForBlock(CurBB)); // Advance to the next block.