diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-11-10 01:08:51 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-11-10 01:08:51 +0000 | 
| commit | fb7f87d5a37d96b6b6940a8cfc69b1511316311c (patch) | |
| tree | 4f5c635455faad1e3e79d5878675376a9100390a /llvm/lib | |
| parent | b40d3f76a01406b9f21de5e73aa0ff0274b8e96c (diff) | |
| download | bcm5719-llvm-fb7f87d5a37d96b6b6940a8cfc69b1511316311c.tar.gz bcm5719-llvm-fb7f87d5a37d96b6b6940a8cfc69b1511316311c.zip | |
add a new SimplifyInstruction API, which is like ConstantFoldInstruction, 
except that the result may not be a constant.  Switch jump threading to 
use it so that it gets things like (X & 0) -> 0, which occur when phi preds
are deleted and the remaining phi pred was a zero.
llvm-svn: 86637
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 11 | 
2 files changed, 25 insertions, 6 deletions
| diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 3c1529ce6df..6953f16dc92 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -291,3 +291,23 @@ Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,    return SimplifyFCmpInst(Predicate, LHS, RHS, TD);  } + +/// SimplifyInstruction - See if we can compute a simplified version of this +/// instruction.  If not, this returns null. +Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD) { +  switch (I->getOpcode()) { +  default: +    return ConstantFoldInstruction(I, TD); +  case Instruction::And: +    return SimplifyAndInst(I->getOperand(0), I->getOperand(1), TD); +  case Instruction::Or: +    return SimplifyOrInst(I->getOperand(0), I->getOperand(1), TD); +  case Instruction::ICmp: +    return SimplifyICmpInst(cast<ICmpInst>(I)->getPredicate(), +                            I->getOperand(0), I->getOperand(1), TD); +  case Instruction::FCmp: +    return SimplifyFCmpInst(cast<FCmpInst>(I)->getPredicate(), +                            I->getOperand(0), I->getOperand(1), TD); +  } +} + diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 7eaae9b36f1..46d40ef5d15 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -16,7 +16,6 @@  #include "llvm/IntrinsicInst.h"  #include "llvm/LLVMContext.h"  #include "llvm/Pass.h" -#include "llvm/Analysis/ConstantFolding.h"  #include "llvm/Analysis/InstructionSimplify.h"  #include "llvm/Transforms/Utils/BasicBlockUtils.h"  #include "llvm/Transforms/Utils/Local.h" @@ -223,9 +222,9 @@ static void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,        Instruction *User = cast<Instruction>(U.getUser());        U = PNV; -      // See if we can simplify it (constant folding). -      if (Constant *C = ConstantFoldInstruction(User, TD)) { -        User->replaceAllUsesWith(C); +      // See if we can simplify it. +      if (Value *V = SimplifyInstruction(User, TD)) { +        User->replaceAllUsesWith(V);          User->eraseFromParent();        }      } @@ -1203,8 +1202,8 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,    BI = NewBB->begin();    for (BasicBlock::iterator E = NewBB->end(); BI != E; ) {      Instruction *Inst = BI++; -    if (Constant *C = ConstantFoldInstruction(Inst, TD)) { -      Inst->replaceAllUsesWith(C); +    if (Value *V = SimplifyInstruction(Inst, TD)) { +      Inst->replaceAllUsesWith(V);        Inst->eraseFromParent();        continue;      } | 

