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

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 12 11:41:01 PST 2004


Changes in directory llvm/lib/Transforms/Scalar:

SCCP.cpp updated: 1.85 -> 1.86

---
Log message:

Fix fairly severe bug in my last checking where we treated all unfoldable 
constants as being "true" when evaluating branches.  This was introduced
because we now create constantexprs for the constants instead of failing the
fold.


---
Diffs of the changes:  (+12 -3)

Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.85 llvm/lib/Transforms/Scalar/SCCP.cpp:1.86
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.85	Sun Jan 11 22:29:41 2004
+++ llvm/lib/Transforms/Scalar/SCCP.cpp	Mon Jan 12 11:40:36 2004
@@ -362,8 +362,10 @@
       Succs[0] = true;
     } else {
       InstVal &BCValue = getValueState(BI->getCondition());
-      if (BCValue.isOverdefined()) {
-        // Overdefined condition variables mean the branch could go either way.
+      if (BCValue.isOverdefined() ||
+          (BCValue.isConstant() && !isa<ConstantBool>(BCValue.getConstant()))) {
+        // Overdefined condition variables, and branches on unfoldable constant
+        // conditions, mean the branch could go either way.
         Succs[0] = Succs[1] = true;
       } else if (BCValue.isConstant()) {
         // Constant condition variables mean the branch can only go a single way
@@ -375,7 +377,8 @@
     Succs[0] = Succs[1] = true;
   } else if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) {
     InstVal &SCValue = getValueState(SI->getCondition());
-    if (SCValue.isOverdefined()) {  // Overdefined condition?
+    if (SCValue.isOverdefined() ||   // Overdefined condition?
+        (SCValue.isConstant() && !isa<ConstantInt>(SCValue.getConstant()))) {
       // All destinations are executable!
       Succs.assign(TI.getNumSuccessors(), true);
     } else if (SCValue.isConstant()) {
@@ -419,6 +422,9 @@
         // Overdefined condition variables mean the branch could go either way.
         return true;
       } else if (BCValue.isConstant()) {
+        // Not branching on an evaluatable constant?
+        if (!isa<ConstantBool>(BCValue.getConstant())) return true;
+
         // Constant condition variables mean the branch can only go a single way
         return BI->getSuccessor(BCValue.getConstant() == 
                                        ConstantBool::False) == To;
@@ -435,6 +441,9 @@
       return true;
     } else if (SCValue.isConstant()) {
       Constant *CPV = SCValue.getConstant();
+      if (!isa<ConstantInt>(CPV))
+        return true;  // not a foldable constant?
+
       // Make sure to skip the "default value" which isn't a value
       for (unsigned i = 1, E = SI->getNumSuccessors(); i != E; ++i)
         if (SI->getSuccessorValue(i) == CPV) // Found the taken branch...





More information about the llvm-commits mailing list