From c93843f1e4727f6ce132db98e2b9326e053580b1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 1 Jan 2010 22:29:12 +0000 Subject: 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 --- include/llvm/Support/PatternMatch.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'include/llvm/Support/PatternMatch.h') diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index c0b6a6b..23daad9 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -437,7 +437,7 @@ m_SelectCst(const Cond &C) { // Matchers for CastInst classes // -template +template struct CastClass_match { Op_t Op; @@ -445,17 +445,28 @@ struct CastClass_match { template bool match(OpTy *V) { - if (Class *I = dyn_cast(V)) - return Op.match(I->getOperand(0)); + if (CastInst *I = dyn_cast(V)) + return I->getOpcode() == Opcode && Op.match(I->getOperand(0)); + if (ConstantExpr *CE = dyn_cast(V)) + return CE->getOpcode() == Opcode && Op.match(CE->getOperand(0)); return false; } }; -template -inline CastClass_match m_Cast(const OpTy &Op) { - return CastClass_match(Op); +/// m_PtrToInt +template +inline CastClass_match +m_PtrToInt(const OpTy &Op) { + return CastClass_match(Op); } +/// m_Trunc +template +inline CastClass_match +m_Trunc(const OpTy &Op) { + return CastClass_match(Op); +} + //===----------------------------------------------------------------------===// // Matchers for unary operators -- cgit v1.1