[llvm-commits] [llvm] r92400 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Fri Jan 1 14:12:04 PST 2010


Author: lattner
Date: Fri Jan  1 16:12:03 2010
New Revision: 92400

URL: http://llvm.org/viewvc/llvm-project?rev=92400&view=rev
Log:
use 'match' to simplify some code.

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

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jan  1 16:12:03 2010
@@ -2949,12 +2949,11 @@
   // Optimize pointer differences into the same array into a size.  Consider:
   //  &A[10] - &A[0]: we should compile this to "10".
   if (TD) {
-    if (PtrToIntInst *LHS = dyn_cast<PtrToIntInst>(Op0))
-      if (PtrToIntInst *RHS = dyn_cast<PtrToIntInst>(Op1))
-        if (Value *Res = OptimizePointerDifference(LHS->getOperand(0),
-                                                   RHS->getOperand(0),
-                                                   I.getType()))
-          return ReplaceInstUsesWith(I, Res);
+    Value *LHSOp, *RHSOp;
+    if (match(Op0, m_Cast<PtrToIntInst>(m_Value(LHSOp))) &&
+        match(Op1, m_Cast<PtrToIntInst>(m_Value(RHSOp))))
+      if (Value *Res = OptimizePointerDifference(LHSOp, RHSOp, I.getType()))
+        return ReplaceInstUsesWith(I, Res);
     
     // trunc(p)-trunc(q) -> trunc(p-q)
     if (TruncInst *LHST = dyn_cast<TruncInst>(Op0))





More information about the llvm-commits mailing list