[llvm-commits] CVS: llvm/lib/Transforms/Scalar/SCCP.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Dec 10 22:06:08 PST 2004



Changes in directory llvm/lib/Transforms/Scalar:

SCCP.cpp updated: 1.117 -> 1.118
---
Log message:

Two bug fixes:
 1. Actually increment the Statistic for the GV elim optzn
 2. When resolving undef branches, only resolve branches in executable blocks,
    avoiding marking a bunch of completely dead blocks live.  This has a big
    impact on the quality of the generated code.

With this patch, we positively rip up vortex, compiling Ut_MoveBytes to a
single memcpy call. In vortex we get this:

     12 ipsccp           - Number of globals found to be constant
    986 ipsccp           - Number of arguments constant propagated
   1378 ipsccp           - Number of basic blocks unreachable
   8919 ipsccp           - Number of instructions removed





---
Diffs of the changes:  (+27 -17)

Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.117 llvm/lib/Transforms/Scalar/SCCP.cpp:1.118
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.117	Fri Dec 10 23:32:19 2004
+++ llvm/lib/Transforms/Scalar/SCCP.cpp	Sat Dec 11 00:05:53 2004
@@ -217,7 +217,11 @@
   
   inline void markOverdefined(LatticeVal &IV, Value *V) {
     if (IV.markOverdefined()) {
-      DEBUG(std::cerr << "markOverdefined: " << *V);
+      DEBUG(std::cerr << "markOverdefined: ";
+            if (Function *F = dyn_cast<Function>(V))
+              std::cerr << "Function '" << F->getName() << "'\n";
+            else
+              std::cerr << *V);
       // Only instructions go on the work list
       OverdefinedInstWorkList.push_back(V);
     }
@@ -934,26 +938,29 @@
 /// should be rerun.
 bool SCCPSolver::ResolveBranchesIn(Function &F) {
   bool BranchesResolved = false;
-  for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
-    TerminatorInst *TI = BB->getTerminator();
-    if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
-      if (BI->isConditional()) {
-        LatticeVal &BCValue = getValueState(BI->getCondition());
-        if (BCValue.isUndefined()) {
-          BI->setCondition(ConstantBool::True);
+  for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
+    if (BBExecutable.count(BB)) {
+      TerminatorInst *TI = BB->getTerminator();
+      if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
+        if (BI->isConditional()) {
+          LatticeVal &BCValue = getValueState(BI->getCondition());
+          if (BCValue.isUndefined()) {
+            BI->setCondition(ConstantBool::True);
+            BranchesResolved = true;
+            visit(BI);
+          }
+        }
+      } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+        LatticeVal &SCValue = getValueState(SI->getCondition());
+        if (SCValue.isUndefined()) {
+          const Type *CondTy = SI->getCondition()->getType();
+          SI->setCondition(Constant::getNullValue(CondTy));
           BranchesResolved = true;
-          visit(BI);
+          visit(SI);
         }
       }
-    } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
-      LatticeVal &SCValue = getValueState(SI->getCondition());
-      if (SCValue.isUndefined()) {
-        SI->setCondition(Constant::getNullValue(SI->getCondition()->getType()));
-        BranchesResolved = true;
-        visit(SI);
-      }
     }
-  }
+
   return BranchesResolved;
 }
 
@@ -1007,6 +1014,7 @@
   bool ResolvedBranches = true;
   while (ResolvedBranches) {
     Solver.Solve();
+    DEBUG(std::cerr << "RESOLVING UNDEF BRANCHES\n");
     ResolvedBranches = Solver.ResolveBranchesIn(F);
   }
 
@@ -1146,6 +1154,7 @@
   while (ResolvedBranches) {
     Solver.Solve();
 
+    DEBUG(std::cerr << "RESOLVING UNDEF BRANCHES\n");
     ResolvedBranches = false;
     for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
       ResolvedBranches |= Solver.ResolveBranchesIn(*F);
@@ -1284,6 +1293,7 @@
       SI->eraseFromParent();
     }
     M.getGlobalList().erase(GV);
+    ++IPNumGlobalConst;
   }
   
   return MadeChanges;






More information about the llvm-commits mailing list