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 | f2ebc682d1ee008782d44261f28e92bf982790c2 (patch) | |
tree | b2626bebd963858de49c9c0017afac91d0d102f7 /include | |
parent | 33767185055399d729e2a1b2c24d4d36efab125c (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 'include')
-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 c0b6a6b98c..23daad9239 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 |