[llvm-commits] [llvm] r86886 - /llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp

Chris Lattner sabre at nondot.org
Wed Nov 11 14:31:38 PST 2009


Author: lattner
Date: Wed Nov 11 16:31:38 2009
New Revision: 86886

URL: http://llvm.org/viewvc/llvm-project?rev=86886&view=rev
Log:
pass TD into a SimplifyCmpInst call.  Add another case that
uses LVI info when -enable-jump-threading-lvi is passed.

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

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Wed Nov 11 16:31:38 2009
@@ -361,7 +361,7 @@
         Value *LHS = PN->getIncomingValue(i);
         Value *RHS = Cmp->getOperand(1)->DoPHITranslation(BB, PredBB);
         
-        Value *Res = SimplifyCmpInst(Cmp->getPredicate(), LHS, RHS);
+        Value *Res = SimplifyCmpInst(Cmp->getPredicate(), LHS, RHS, TD);
         if (Res == 0) continue;
         
         if (isa<UndefValue>(Res))
@@ -373,8 +373,29 @@
       return !Result.empty();
     }
     
-    // TODO: We could also recurse to see if we can determine constants another
-    // way.
+    
+    // If comparing a live-in value against a constant, see if we know the
+    // live-in value on any predecessors.
+    if (LVI && isa<Constant>(Cmp->getOperand(1)) &&
+        (!isa<Instruction>(Cmp->getOperand(0)) ||
+         cast<Instruction>(Cmp->getOperand(0))->getParent() != BB)) {
+      Constant *RHSCst = cast<Constant>(Cmp->getOperand(1));
+      
+      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.
+        Constant *PredCst = LVI->getConstant(Cmp->getOperand(0), *PI);
+        if (PredCst == 0)
+          continue;
+        
+        // Constant fold the compare.
+        Value *Res = SimplifyCmpInst(Cmp->getPredicate(), PredCst, RHSCst, TD);
+        if (isa<ConstantInt>(Res) || isa<UndefValue>(Res))
+          Result.push_back(std::make_pair(dyn_cast<ConstantInt>(Res), *PI));
+      }
+      
+      return !Result.empty();
+    }
   }
   return false;
 }





More information about the llvm-commits mailing list