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
This commit is contained in:
Chris Lattner
2009-11-10 01:08:51 +00:00
parent b40d3f76a0
commit fb7f87d5a3
3 changed files with 30 additions and 7 deletions

View File

@@ -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;
}