use 'match' to simplify some code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92400 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-01-01 22:12:03 +00:00
parent e33d413152
commit 3376718505

View File

@ -2949,11 +2949,10 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
// Optimize pointer differences into the same array into a size. Consider: // Optimize pointer differences into the same array into a size. Consider:
// &A[10] - &A[0]: we should compile this to "10". // &A[10] - &A[0]: we should compile this to "10".
if (TD) { if (TD) {
if (PtrToIntInst *LHS = dyn_cast<PtrToIntInst>(Op0)) Value *LHSOp, *RHSOp;
if (PtrToIntInst *RHS = dyn_cast<PtrToIntInst>(Op1)) if (match(Op0, m_Cast<PtrToIntInst>(m_Value(LHSOp))) &&
if (Value *Res = OptimizePointerDifference(LHS->getOperand(0), match(Op1, m_Cast<PtrToIntInst>(m_Value(RHSOp))))
RHS->getOperand(0), if (Value *Res = OptimizePointerDifference(LHSOp, RHSOp, I.getType()))
I.getType()))
return ReplaceInstUsesWith(I, Res); return ReplaceInstUsesWith(I, Res);
// trunc(p)-trunc(q) -> trunc(p-q) // trunc(p)-trunc(q) -> trunc(p-q)