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

Chris Lattner sabre at nondot.org
Mon Nov 9 15:00:14 PST 2009


Author: lattner
Date: Mon Nov  9 17:00:14 2009
New Revision: 86616

URL: http://llvm.org/viewvc/llvm-project?rev=86616&view=rev
Log:
use instructionsimplify instead of a weak clone of ad-hoc folding stuff.

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=86616&r1=86615&r2=86616&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Mon Nov  9 17:00:14 2009
@@ -17,6 +17,7 @@
 #include "llvm/LLVMContext.h"
 #include "llvm/Pass.h"
 #include "llvm/Analysis/ConstantFolding.h"
+#include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Transforms/Utils/SSAUpdater.h"
@@ -203,7 +204,6 @@
   // Remove the entries for Pred from the PHI nodes in BB, but do not simplify
   // them down.  This will leave us with single entry phi nodes and other phis
   // that can be removed.
-  //BB->removePredecessor(Pred, true);
   BB->removePredecessor(Pred, true);
   
   WeakVH PhiIt = &BB->front();
@@ -266,26 +266,6 @@
     LoopHeaders.insert(const_cast<BasicBlock*>(Edges[i].second));
 }
 
-/// GetResultOfComparison - Given an icmp/fcmp predicate and the left and right
-/// hand sides of the compare instruction, try to determine the result. If the
-/// result can not be determined, a null pointer is returned.
-static Constant *GetResultOfComparison(CmpInst::Predicate pred,
-                                       Value *LHS, Value *RHS) {
-  if (Constant *CLHS = dyn_cast<Constant>(LHS))
-    if (Constant *CRHS = dyn_cast<Constant>(RHS))
-      return ConstantExpr::getCompare(pred, CLHS, CRHS);
-  
-  if (LHS == RHS)
-    if (isa<IntegerType>(LHS->getType()) || isa<PointerType>(LHS->getType())) {
-      if (ICmpInst::isTrueWhenEqual(pred))
-        return ConstantInt::getTrue(LHS->getContext());
-      else
-        return ConstantInt::getFalse(LHS->getContext());
-    }
-  return 0;
-}
-
-
 /// ComputeValueKnownInPredecessors - Given a basic block BB and a value V, see
 /// if we can infer that the value is a known ConstantInt in any of our
 /// predecessors.  If so, return the known list of value and pred BB in the
@@ -374,7 +354,7 @@
         Value *LHS = PN->getIncomingValue(i);
         Value *RHS = Cmp->getOperand(1)->DoPHITranslation(BB, PredBB);
         
-        Constant *Res = GetResultOfComparison(Cmp->getPredicate(), LHS, RHS);
+        Value *Res = SimplifyCompare(Cmp->getPredicate(), LHS, RHS);
         if (Res == 0) continue;
         
         if (isa<UndefValue>(Res))





More information about the llvm-commits mailing list