[llvm-commits] [llvm] r119055 - in /llvm/trunk: include/llvm/Analysis/InstructionSimplify.h include/llvm/Instructions.h lib/Analysis/InstructionSimplify.cpp lib/Transforms/Scalar/GVN.cpp lib/Transforms/Scalar/LoopUnswitch.cpp lib/VMCore/Instructions.cpp

Duncan Sands baldrick at free.fr
Sun Nov 14 10:36:11 PST 2010


Author: baldrick
Date: Sun Nov 14 12:36:10 2010
New Revision: 119055

URL: http://llvm.org/viewvc/llvm-project?rev=119055&view=rev
Log:
If dom tree information is available, make it possible to pass
it to get better phi node simplification.

Modified:
    llvm/trunk/include/llvm/Analysis/InstructionSimplify.h
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp
    llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Analysis/InstructionSimplify.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InstructionSimplify.h?rev=119055&r1=119054&r2=119055&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/InstructionSimplify.h (original)
+++ llvm/trunk/include/llvm/Analysis/InstructionSimplify.h Sun Nov 14 12:36:10 2010
@@ -17,6 +17,7 @@
 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
 
 namespace llvm {
+  class DominatorTree;
   class Instruction;
   class Value;
   class TargetData;
@@ -73,7 +74,8 @@
   /// instruction.  If not, this returns null.
   /// WARNING: If called on unreachable code, an instruction may be reported
   /// to simplify to itself.
-  Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0);
+  Value *SimplifyInstruction(Instruction *I, const TargetData *TD = 0,
+                             const DominatorTree *DT = 0);
 
 
   /// ReplaceAndSimplifyAllUses - Perform From->replaceAllUsesWith(To) and then
@@ -83,7 +85,8 @@
   /// simplifies and deletes scalar operations, it does not change the CFG.
   ///
   void ReplaceAndSimplifyAllUses(Instruction *From, Value *To,
-                                 const TargetData *TD = 0);
+                                 const TargetData *TD = 0,
+                                 const DominatorTree *DT = 0);
 } // end namespace llvm
 
 #endif

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=119055&r1=119054&r2=119055&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Sun Nov 14 12:36:10 2010
@@ -1952,7 +1952,7 @@
   /// value dominates the PHI. If DT is null, use a conservative check,
   /// otherwise use DT to test for dominance.
   ///
-  Value *hasConstantValue(DominatorTree *DT = 0) const;
+  Value *hasConstantValue(const DominatorTree *DT = 0) const;
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const PHINode *) { return true; }

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=119055&r1=119054&r2=119055&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Nov 14 12:36:10 2010
@@ -674,7 +674,8 @@
 
 /// 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 @@
     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 @@
 /// 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 @@
       // 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;
 

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=119055&r1=119054&r2=119055&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sun Nov 14 12:36:10 2010
@@ -1903,7 +1903,7 @@
   // 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);

Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp?rev=119055&r1=119054&r2=119055&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp Sun Nov 14 12:36:10 2010
@@ -994,7 +994,7 @@
     // 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;
     }

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=119055&r1=119054&r2=119055&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Sun Nov 14 12:36:10 2010
@@ -170,7 +170,7 @@
 /// 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





More information about the llvm-commits mailing list