diff options
author | Duncan Sands <baldrick@free.fr> | 2010-11-14 18:36:10 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2010-11-14 18:36:10 +0000 |
commit | eff0581583ef10e2872e9baf537a04b67d992101 (patch) | |
tree | 4aff00b570f7058263f492f0ec91f8e59119547a /lib | |
parent | 0094345184bc0a791f0811c8d7f5b6f9c8296e0f (diff) | |
download | external_llvm-eff0581583ef10e2872e9baf537a04b67d992101.zip external_llvm-eff0581583ef10e2872e9baf537a04b67d992101.tar.gz external_llvm-eff0581583ef10e2872e9baf537a04b67d992101.tar.bz2 |
If dom tree information is available, make it possible to pass
it to get better phi node simplification.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119055 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/InstructionSimplify.cpp | 12 | ||||
-rw-r--r-- | lib/Transforms/Scalar/GVN.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LoopUnswitch.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 2 |
4 files changed, 10 insertions, 8 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index 210399d..282e0d3 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -674,7 +674,8 @@ Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, /// 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) { +Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD, + const DominatorTree *DT) { switch (I->getOpcode()) { default: return ConstantFoldInstruction(I, TD); @@ -700,7 +701,7 @@ Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD) { return SimplifyGEPInst(&Ops[0], Ops.size(), TD); } case Instruction::PHI: - return cast<PHINode>(I)->hasConstantValue(); + return cast<PHINode>(I)->hasConstantValue(DT); } } @@ -711,7 +712,8 @@ Value *llvm::SimplifyInstruction(Instruction *I, const TargetData *TD) { /// simplifies and deletes scalar operations, it does not change the CFG. /// void llvm::ReplaceAndSimplifyAllUses(Instruction *From, Value *To, - const TargetData *TD) { + const TargetData *TD, + const DominatorTree *DT) { assert(From != To && "ReplaceAndSimplifyAllUses(X,X) is not valid!"); // FromHandle/ToHandle - This keeps a WeakVH on the from/to values so that @@ -735,12 +737,12 @@ void llvm::ReplaceAndSimplifyAllUses(Instruction *From, Value *To, // SimplifyInstruction. AssertingVH<> UserHandle(User); - SimplifiedVal = SimplifyInstruction(User, TD); + SimplifiedVal = SimplifyInstruction(User, TD, DT); if (SimplifiedVal == 0) continue; } // Recursively simplify this user to the new value. - ReplaceAndSimplifyAllUses(User, SimplifiedVal, TD); + ReplaceAndSimplifyAllUses(User, SimplifiedVal, TD, DT); From = dyn_cast_or_null<Instruction>((Value*)FromHandle); To = ToHandle; diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index db3cd80..732f6c8 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1903,7 +1903,7 @@ bool GVN::processInstruction(Instruction *I, // to value numbering it. Value numbering often exposes redundancies, for // example if it determines that %y is equal to %x then the instruction // "%z = and i32 %x, %y" becomes "%z = and i32 %x, %x" which we now simplify. - if (Value *V = SimplifyInstruction(I, TD)) { + if (Value *V = SimplifyInstruction(I, TD, DT)) { I->replaceAllUsesWith(V); if (MD && V->getType()->isPointerTy()) MD->invalidateCachedPointerInfo(V); diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index eb05f99..009ee7b 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -994,7 +994,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { // See if instruction simplification can hack this up. This is common for // things like "select false, X, Y" after unswitching made the condition be // 'false'. - if (Value *V = SimplifyInstruction(I)) { + if (Value *V = SimplifyInstruction(I, 0, DT)) { ReplaceUsesOfWith(I, V, Worklist, L, LPM); continue; } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 57181e3..7306d86 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -170,7 +170,7 @@ void PHINode::resizeOperands(unsigned NumOps) { /// value dominates the PHI. If DT is null, use a conservative check, /// otherwise use DT to test for dominance. /// -Value *PHINode::hasConstantValue(DominatorTree *DT) const { +Value *PHINode::hasConstantValue(const DominatorTree *DT) const { // If the PHI node only has one incoming value, eliminate the PHI node. if (getNumIncomingValues() == 1) { if (getIncomingValue(0) != this) // not X = phi X |