[llvm-commits] [llvm] r41081 - /llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Owen Anderson resistor at mac.com
Tue Aug 14 11:33:27 PDT 2007


Author: resistor
Date: Tue Aug 14 13:33:27 2007
New Revision: 41081

URL: http://llvm.org/viewvc/llvm-project?rev=41081&view=rev
Log:
Eliminate PHI nodes with constant values during normal GVN processing, even when
they're not related to eliminating a load.

Modified:
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=41081&r1=41080&r2=41081&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Tue Aug 14 13:33:27 2007
@@ -946,7 +946,27 @@
   
   unsigned num = VN.lookup_or_add(I);
   
-  if (currAvail.test(num)) {
+  if (PHINode* p = dyn_cast<PHINode>(I)) {
+    Value* constVal = p->hasConstantValue();
+    
+    if (constVal) {
+      if (Instruction* inst = dyn_cast<Instruction>(constVal)) {
+        DominatorTree &DT = getAnalysis<DominatorTree>();  
+        if (DT.dominates(inst, p)) {
+          for (PhiMapType::iterator PI = phiMap.begin(), PE = phiMap.end();
+               PI != PE; ++PI)
+            if (PI->second.count(p))
+              PI->second.erase(p);
+        
+          p->replaceAllUsesWith(inst);
+          toErase.push_back(p);
+        }
+      } else {
+        p->replaceAllUsesWith(constVal);
+        toErase.push_back(p);
+      }
+    }
+  } else if (currAvail.test(num)) {
     Value* repl = find_leader(currAvail, num);
     
     VN.erase(I);





More information about the llvm-commits mailing list