diff options
author | Duncan Sands <baldrick@free.fr> | 2011-02-07 09:36:32 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2011-02-07 09:36:32 +0000 |
commit | 163a84bbce69947aa314760e6068c704fc0df7a0 (patch) | |
tree | 4c45912de2fe18eee154b43593182969e3479ce7 /include | |
parent | 1dbf0df996bba398a70abccc714b1a9652330014 (diff) | |
download | external_llvm-163a84bbce69947aa314760e6068c704fc0df7a0.zip external_llvm-163a84bbce69947aa314760e6068c704fc0df7a0.tar.gz external_llvm-163a84bbce69947aa314760e6068c704fc0df7a0.tar.bz2 |
Add an m_Div pattern for matching either a udiv or an sdiv and use it
to simplify the "(X/Y)*Y->X when the division is exact" transform.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Support/PatternMatch.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index cb94fe5..2d5ca8e 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -347,6 +347,40 @@ inline Shr_match<LHS, RHS> m_Shr(const LHS &L, const RHS &R) { } //===----------------------------------------------------------------------===// +// Matchers for either SDiv or UDiv .. for convenience +// +template<typename LHS_t, typename RHS_t, typename ConcreteTy = BinaryOperator> +struct Div_match { + LHS_t L; + RHS_t R; + + Div_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {} + + template<typename OpTy> + bool match(OpTy *V) { + if (V->getValueID() == Value::InstructionVal + Instruction::SDiv || + V->getValueID() == Value::InstructionVal + Instruction::UDiv) { + ConcreteTy *I = cast<ConcreteTy>(V); + return (I->getOpcode() == Instruction::UDiv || + I->getOpcode() == Instruction::SDiv) && + L.match(I->getOperand(0)) && + R.match(I->getOperand(1)); + } + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) + return (CE->getOpcode() == Instruction::SDiv || + CE->getOpcode() == Instruction::UDiv) && + L.match(CE->getOperand(0)) && + R.match(CE->getOperand(1)); + return false; + } +}; + +template<typename LHS, typename RHS> +inline Div_match<LHS, RHS> m_Div(const LHS &L, const RHS &R) { + return Div_match<LHS, RHS>(L, R); +} + +//===----------------------------------------------------------------------===// // Matchers for binary classes // |