various fixes to the lattice transfer functions.
authorChris Lattner <sabre@nondot.org>
Thu, 12 Nov 2009 04:57:13 +0000 (04:57 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 12 Nov 2009 04:57:13 +0000 (04:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86952 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LazyValueInfo.cpp
lib/Transforms/Scalar/JumpThreading.cpp

index 659fa471aa82a0df257f59d93afbff4e9c61414f..d569b8595d1addea4b60ff4f2c4830a801a845f3 100644 (file)
@@ -141,19 +141,40 @@ public:
 
     if (RHS.isNotConstant()) {
       if (isNotConstant()) {
-        if (getNotConstant() != RHS.getNotConstant())
+        if (getNotConstant() != RHS.getNotConstant() ||
+            isa<ConstantExpr>(getNotConstant()) ||
+            isa<ConstantExpr>(RHS.getNotConstant()))
           return markOverdefined();
         return false;
       }
-      if (isConstant() && getConstant() != RHS.getNotConstant())
-        return markOverdefined();
+      if (isConstant()) {
+        if (getConstant() == RHS.getNotConstant() ||
+            isa<ConstantExpr>(RHS.getNotConstant()) ||
+            isa<ConstantExpr>(getConstant()))
+          return markOverdefined();
+        return markNotConstant(RHS.getNotConstant());
+      }
+      
+      assert(isUndefined() && "Unexpected lattice");
       return markNotConstant(RHS.getNotConstant());
     }
     
-    // RHS must be a constant, we must be undef or constant.
-    if (isConstant() && getConstant() != RHS.getConstant())
+    // RHS must be a constant, we must be undef, constant, or notconstant.
+    if (isUndefined())
+      return markConstant(RHS.getConstant());
+    
+    if (isConstant()) {
+      if (getConstant() != RHS.getConstant())
+        return markOverdefined();
+      return false;
+    }
+
+    // If we are known "!=4" and RHS is "==5", stay at "!=4".
+    if (getNotConstant() == RHS.getConstant() ||
+        isa<ConstantExpr>(getNotConstant()) ||
+        isa<ConstantExpr>(RHS.getConstant()))
       return markOverdefined();
-    return markConstant(RHS.getConstant());
+    return false;
   }
   
 };
index e7a87e098d04a23a14ea38c88d3b1df5a0030621..1bfad2d5d7ea8d7789a37fa97777c927af839a71 100644 (file)
@@ -275,6 +275,12 @@ ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,PredValueInfo &Result){
     /// predecessor based on its terminator.
     //
     if (LVI) {
+      // FIXME: change this to use the more-rich 'getPredicateOnEdge' method if
+      // "I" is a non-local compare-with-a-constant instruction.  This would be
+      // able to handle value inequalities better, for example if the compare is
+      // "X < 4" and "X < 3" is known true but "X < 4" itself is not available.
+      // Perhaps getConstantOnEdge should be smart enough to do this?
+      
       for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
         // If the value is known by LazyValueInfo to be a constant in a
         // predecessor, use that information to try to thread this block.