aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-01-01 22:29:12 +0000
committerChris Lattner <sabre@nondot.org>2010-01-01 22:29:12 +0000
commitf2ebc682d1ee008782d44261f28e92bf982790c2 (patch)
treeb2626bebd963858de49c9c0017afac91d0d102f7 /lib/Transforms/Scalar/InstructionCombining.cpp
parent33767185055399d729e2a1b2c24d4d36efab125c (diff)
teach instcombine to optimize pointer difference idioms involving constant
expressions. This is a step towards comment #4 in PR3351. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92401 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index ee0b9374cb..6c5a16c361 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2950,20 +2950,16 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
// &A[10] - &A[0]: we should compile this to "10".
if (TD) {
Value *LHSOp, *RHSOp;
- if (match(Op0, m_Cast<PtrToIntInst>(m_Value(LHSOp))) &&
- match(Op1, m_Cast<PtrToIntInst>(m_Value(RHSOp))))
+ if (match(Op0, m_PtrToInt(m_Value(LHSOp))) &&
+ match(Op1, m_PtrToInt(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))
- if (TruncInst *RHST = dyn_cast<TruncInst>(Op1))
- if (PtrToIntInst *LHS = dyn_cast<PtrToIntInst>(LHST->getOperand(0)))
- if (PtrToIntInst *RHS = dyn_cast<PtrToIntInst>(RHST->getOperand(0)))
- if (Value *Res = OptimizePointerDifference(LHS->getOperand(0),
- RHS->getOperand(0),
- I.getType()))
- return ReplaceInstUsesWith(I, Res);
+ if (match(Op0, m_Trunc(m_PtrToInt(m_Value(LHSOp)))) &&
+ match(Op1, m_Trunc(m_PtrToInt(m_Value(RHSOp)))))
+ if (Value *Res = OptimizePointerDifference(LHSOp, RHSOp, I.getType()))
+ return ReplaceInstUsesWith(I, Res);
}
return 0;