aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Support/PatternMatch.h
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-11-08 06:47:33 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-11-08 06:47:33 +0000
commit3822ff5c71478c7c90a50ca57045fb676fcb5005 (patch)
tree44d109d0052024ecdbcfceb248446b56a7bfce0f /include/llvm/Support/PatternMatch.h
parent73fb07566b24d43bb116c2ade0297d90ec72490d (diff)
downloadexternal_llvm-3822ff5c71478c7c90a50ca57045fb676fcb5005.tar.gz
external_llvm-3822ff5c71478c7c90a50ca57045fb676fcb5005.tar.bz2
external_llvm-3822ff5c71478c7c90a50ca57045fb676fcb5005.zip
For PR950:
This patch converts the old SHR instruction into two instructions, AShr (Arithmetic) and LShr (Logical). The Shr instructions now are not dependent on the sign of their operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31542 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/PatternMatch.h')
-rw-r--r--include/llvm/Support/PatternMatch.h46
1 files changed, 43 insertions, 3 deletions
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h
index 2d498a3561..56f7a9c4f9 100644
--- a/include/llvm/Support/PatternMatch.h
+++ b/include/llvm/Support/PatternMatch.h
@@ -172,9 +172,49 @@ inline BinaryOp_match<LHS, RHS, Instruction::Shl,
}
template<typename LHS, typename RHS>
-inline BinaryOp_match<LHS, RHS, Instruction::Shr,
- ShiftInst> m_Shr(const LHS &L, const RHS &R) {
- return BinaryOp_match<LHS, RHS, Instruction::Shr, ShiftInst>(L, R);
+inline BinaryOp_match<LHS, RHS, Instruction::LShr,
+ ShiftInst> m_LShr(const LHS &L, const RHS &R) {
+ return BinaryOp_match<LHS, RHS, Instruction::LShr, ShiftInst>(L, R);
+}
+
+template<typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, Instruction::AShr,
+ ShiftInst> m_AShr(const LHS &L, const RHS &R) {
+ return BinaryOp_match<LHS, RHS, Instruction::AShr, ShiftInst>(L, R);
+}
+
+//===----------------------------------------------------------------------===//
+// Matchers for either AShr or LShr .. for convenience
+//
+template<typename LHS_t, typename RHS_t, typename ConcreteTy = ShiftInst>
+struct Shr_match {
+ LHS_t L;
+ RHS_t R;
+
+ Shr_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
+
+ template<typename OpTy>
+ bool match(OpTy *V) {
+ if (V->getValueType() == Value::InstructionVal + Instruction::LShr ||
+ V->getValueType() == Value::InstructionVal + Instruction::AShr) {
+ ConcreteTy *I = cast<ConcreteTy>(V);
+ return (I->getOpcode() == Instruction::AShr ||
+ I->getOpcode() == Instruction::LShr) &&
+ L.match(I->getOperand(0)) &&
+ R.match(I->getOperand(1));
+ }
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+ return (CE->getOpcode() == Instruction::LShr ||
+ CE->getOpcode() == Instruction::AShr) &&
+ L.match(CE->getOperand(0)) &&
+ R.match(CE->getOperand(1));
+ return false;
+ }
+};
+
+template<typename LHS, typename RHS>
+inline Shr_match<LHS, RHS> m_Shr(const LHS &L, const RHS &R) {
+ return Shr_match<LHS, RHS>(L, R);
}
//===----------------------------------------------------------------------===//