diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-01 22:29:12 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-01 22:29:12 +0000 |
commit | c93843f1e4727f6ce132db98e2b9326e053580b1 (patch) | |
tree | b2626bebd963858de49c9c0017afac91d0d102f7 /include/llvm/Support/PatternMatch.h | |
parent | c49d68ad5762186fa46c83275fcebdb64ceb85e9 (diff) | |
download | external_llvm-c93843f1e4727f6ce132db98e2b9326e053580b1.zip external_llvm-c93843f1e4727f6ce132db98e2b9326e053580b1.tar.gz external_llvm-c93843f1e4727f6ce132db98e2b9326e053580b1.tar.bz2 |
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 'include/llvm/Support/PatternMatch.h')
-rw-r--r-- | include/llvm/Support/PatternMatch.h | 23 |
1 files changed, 17 insertions, 6 deletions
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<typename Op_t, typename Class> +template<typename Op_t, unsigned Opcode> struct CastClass_match { Op_t Op; @@ -445,17 +445,28 @@ struct CastClass_match { template<typename OpTy> bool match(OpTy *V) { - if (Class *I = dyn_cast<Class>(V)) - return Op.match(I->getOperand(0)); + if (CastInst *I = dyn_cast<CastInst>(V)) + return I->getOpcode() == Opcode && Op.match(I->getOperand(0)); + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) + return CE->getOpcode() == Opcode && Op.match(CE->getOperand(0)); return false; } }; -template<typename Class, typename OpTy> -inline CastClass_match<OpTy, Class> m_Cast(const OpTy &Op) { - return CastClass_match<OpTy, Class>(Op); +/// m_PtrToInt +template<typename OpTy> +inline CastClass_match<OpTy, Instruction::PtrToInt> +m_PtrToInt(const OpTy &Op) { + return CastClass_match<OpTy, Instruction::PtrToInt>(Op); } +/// m_Trunc +template<typename OpTy> +inline CastClass_match<OpTy, Instruction::Trunc> +m_Trunc(const OpTy &Op) { + return CastClass_match<OpTy, Instruction::Trunc>(Op); +} + //===----------------------------------------------------------------------===// // Matchers for unary operators |