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

Chris Lattner lattner at cs.uiuc.edu
Sun Mar 19 11:37:36 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

CorrelatedExprs.cpp updated: 1.32 -> 1.33
---
Log message:

Teach cee to propagate through switch statements.  This implements
Transforms/CorrelatedExprs/switch.ll

Patch contributed by Eric Kidd!


---
Diffs of the changes:  (+21 -1)

 CorrelatedExprs.cpp |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp
diff -u llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.32 llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.33
--- llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp:1.32	Thu Jan 26 14:41:32 2006
+++ llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp	Sun Mar 19 13:37:24 2006
@@ -267,6 +267,7 @@
                              const std::vector<BasicBlock*> &RegionExitBlocks);
 
     void PropagateBranchInfo(BranchInst *BI);
+    void PropagateSwitchInfo(SwitchInst *SI);
     void PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI);
     void PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
                            Value *Op1, RegionInfo &RI);
@@ -360,9 +361,12 @@
   // Now that all of our successors have information if they deserve it,
   // propagate any information our terminator instruction finds to our
   // successors.
-  if (BranchInst *BI = dyn_cast<BranchInst>(TI))
+  if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
     if (BI->isConditional())
       PropagateBranchInfo(BI);
+  } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+    PropagateSwitchInfo(SI);
+  }
 
   // If this is a branch to a block outside our region that simply performs
   // another conditional branch, one whose outcome is known inside of this
@@ -794,6 +798,22 @@
 }
 
 
+// PropagateSwitchInfo - We need to propagate the value tested by the
+// switch statement through each case block.
+//
+void CEE::PropagateSwitchInfo(SwitchInst *SI) {
+  // Propagate information down each of our non-default case labels.  We
+  // don't yet propagate information down the default label, because a
+  // potentially large number of inequality constraints provide less
+  // benefit per unit work than a single equality constraint.
+  //
+  Value *cond = SI->getCondition();
+  for (unsigned i = 1; i < SI->getNumSuccessors(); ++i)
+    PropagateEquality(cond, SI->getSuccessorValue(i),
+                      getRegionInfo(SI->getSuccessor(i)));
+}
+
+
 // PropagateEquality - If we discover that two values are equal to each other in
 // a specified region, propagate this knowledge recursively.
 //






More information about the llvm-commits mailing list