diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-08-31 23:00:16 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-08-31 23:00:16 +0000 | 
| commit | 030f02021b6359ec5641622cf1aa63d873ecf55a (patch) | |
| tree | 028e5e93b710ecff0c077629f5064b1aead635c7 /llvm/lib/Transforms | |
| parent | d94dacf82942ada5fff6414e7658f889fea5bcaf (diff) | |
| download | bcm5719-llvm-030f02021b6359ec5641622cf1aa63d873ecf55a.tar.gz bcm5719-llvm-030f02021b6359ec5641622cf1aa63d873ecf55a.zip | |
licm is wasting time hoisting constant foldable operations,
instead of hoisting them, just fold them away.  This occurs in the
testcase for PR8041, for example.
llvm-svn: 112669
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 20 | 
1 files changed, 16 insertions, 4 deletions
| diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index d3d52f5bb42..fa71ab552c2 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -36,11 +36,11 @@  #include "llvm/DerivedTypes.h"  #include "llvm/IntrinsicInst.h"  #include "llvm/Instructions.h" -#include "llvm/Target/TargetData.h" -#include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/LoopPass.h"  #include "llvm/Analysis/AliasAnalysis.h"  #include "llvm/Analysis/AliasSetTracker.h" +#include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/LoopPass.h"  #include "llvm/Analysis/Dominators.h"  #include "llvm/Analysis/ScalarEvolution.h"  #include "llvm/Transforms/Utils/Local.h" @@ -353,6 +353,18 @@ void LICM::HoistRegion(DomTreeNode *N) {      for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ) {        Instruction &I = *II++; +      // Try constant folding this instruction.  If all the operands are +      // constants, it is technically hoistable, but it would be better to just +      // fold it. +      if (Constant *C = ConstantFoldInstruction(&I)) { +        DEBUG(dbgs() << "LICM folding inst: " << I << "  --> " << *C << '\n'); +        CurAST->copyValue(&I, C); +        CurAST->deleteValue(&I); +        I.replaceAllUsesWith(C); +        I.eraseFromParent(); +        continue; +      } +              // Try hoisting the instruction out to the preheader.  We can only do this        // if all of the operands of the instruction are loop invariant and if it        // is safe to hoist the instruction. @@ -360,7 +372,7 @@ void LICM::HoistRegion(DomTreeNode *N) {        if (isLoopInvariantInst(I) && canSinkOrHoistInst(I) &&            isSafeToExecuteUnconditionally(I))          hoist(I); -      } +    }    const std::vector<DomTreeNode*> &Children = N->getChildren();    for (unsigned i = 0, e = Children.size(); i != e; ++i) | 

