diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-10-18 03:00:50 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-10-18 03:00:50 +0000 | 
| commit | a67dd32004bcc1a0a6fa2f0342e584187f5a403d (patch) | |
| tree | d8e3c18960d75895d6170080395fc548c5e21972 /llvm/lib | |
| parent | 8ba9ec9bbbf6625b149ae1ceeb46876553cd2f11 (diff) | |
| download | bcm5719-llvm-a67dd32004bcc1a0a6fa2f0342e584187f5a403d.tar.gz bcm5719-llvm-a67dd32004bcc1a0a6fa2f0342e584187f5a403d.zip | |
Turn store -> null/undef into the LLVM unreachable instruction!  This simple
change hacks off 10K of bytecode from perlbmk (.5%) even though the front-end
is not generating them yet and we are not optimizing the resultant code.
This isn't too bad.
llvm-svn: 17111
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyCFG.cpp | 27 | 
1 files changed, 27 insertions, 0 deletions
| diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFG.cpp index 0f9946e6ee6..af1663c8dbf 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFG.cpp @@ -20,6 +20,8 @@  #include "llvm/Transforms/Scalar.h"  #include "llvm/Transforms/Utils/Local.h" +#include "llvm/Constants.h" +#include "llvm/Instructions.h"  #include "llvm/Module.h"  #include "llvm/Support/CFG.h"  #include "llvm/Pass.h" @@ -45,6 +47,31 @@ static bool MarkAliveBlocks(BasicBlock *BB, std::set<BasicBlock*> &Reachable) {    if (Reachable.count(BB)) return false;    Reachable.insert(BB); +  // Do a quick scan of the basic block, turning any obviously unreachable +  // instructions into LLVM unreachable insts.  The instruction combining pass +  // canonnicalizes unreachable insts into stores to null or undef. +  for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ++BBI) +    if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) +      if (isa<ConstantPointerNull>(SI->getOperand(1)) || +          isa<UndefValue>(SI->getOperand(1))) { +        // Loop over all of the successors, removing BB's entry from any PHI +        // nodes. +        for (succ_iterator I = succ_begin(BB), SE = succ_end(BB); I != SE; ++I) +          (*I)->removePredecessor(BB); + +        new UnreachableInst(SI); +        std::cerr << "Inserted UNREACHABLE instruction!\n"; + +        // All instructions after this are dead. +        for (; BBI != E; ) { +          if (!BBI->use_empty()) +            BBI->replaceAllUsesWith(UndefValue::get(BBI->getType())); +          BB->getInstList().erase(BBI++); +        } +        break; +      } + +    bool Changed = ConstantFoldTerminator(BB);    for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)      MarkAliveBlocks(*SI, Reachable); | 

