Skip to content

[PatternMatch] Use dyn_cast in CastInst_match instead of checking opcode. NFC #79878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions llvm/include/llvm/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1663,14 +1663,14 @@ template <typename Op_t, unsigned Opcode> struct CastOperator_match {
}
};

template <typename Op_t, unsigned Opcode> struct CastInst_match {
template <typename Op_t, typename Class> struct CastInst_match {
Op_t Op;

CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}

template <typename OpTy> bool match(OpTy *V) {
if (auto *I = dyn_cast<Instruction>(V))
return I->getOpcode() == Opcode && Op.match(I->getOperand(0));
if (auto *I = dyn_cast<Class>(V))
return Op.match(I->getOperand(0));
return false;
}
};
Expand Down Expand Up @@ -1698,9 +1698,8 @@ template <typename Op_t> struct NNegZExt_match {
NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}

template <typename OpTy> bool match(OpTy *V) {
if (auto *I = dyn_cast<Instruction>(V))
return I->getOpcode() == Instruction::ZExt && I->hasNonNeg() &&
Op.match(I->getOperand(0));
if (auto *I = dyn_cast<ZExtInst>(V))
return I->hasNonNeg() && Op.match(I->getOperand(0));
return false;
}
};
Expand Down Expand Up @@ -1746,14 +1745,14 @@ m_TruncOrSelf(const OpTy &Op) {

/// Matches SExt.
template <typename OpTy>
inline CastInst_match<OpTy, Instruction::SExt> m_SExt(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::SExt>(Op);
inline CastInst_match<OpTy, SExtInst> m_SExt(const OpTy &Op) {
return CastInst_match<OpTy, SExtInst>(Op);
}

/// Matches ZExt.
template <typename OpTy>
inline CastInst_match<OpTy, Instruction::ZExt> m_ZExt(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::ZExt>(Op);
inline CastInst_match<OpTy, ZExtInst> m_ZExt(const OpTy &Op) {
return CastInst_match<OpTy, ZExtInst>(Op);
}

template <typename OpTy>
Expand All @@ -1762,70 +1761,67 @@ inline NNegZExt_match<OpTy> m_NNegZExt(const OpTy &Op) {
}

template <typename OpTy>
inline match_combine_or<CastInst_match<OpTy, Instruction::ZExt>, OpTy>
inline match_combine_or<CastInst_match<OpTy, ZExtInst>, OpTy>
m_ZExtOrSelf(const OpTy &Op) {
return m_CombineOr(m_ZExt(Op), Op);
}

template <typename OpTy>
inline match_combine_or<CastInst_match<OpTy, Instruction::SExt>, OpTy>
inline match_combine_or<CastInst_match<OpTy, SExtInst>, OpTy>
m_SExtOrSelf(const OpTy &Op) {
return m_CombineOr(m_SExt(Op), Op);
}

/// Match either "sext" or "zext nneg".
template <typename OpTy>
inline match_combine_or<CastInst_match<OpTy, Instruction::SExt>,
NNegZExt_match<OpTy>>
inline match_combine_or<CastInst_match<OpTy, SExtInst>, NNegZExt_match<OpTy>>
m_SExtLike(const OpTy &Op) {
return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
}

template <typename OpTy>
inline match_combine_or<CastInst_match<OpTy, Instruction::ZExt>,
CastInst_match<OpTy, Instruction::SExt>>
inline match_combine_or<CastInst_match<OpTy, ZExtInst>,
CastInst_match<OpTy, SExtInst>>
m_ZExtOrSExt(const OpTy &Op) {
return m_CombineOr(m_ZExt(Op), m_SExt(Op));
}

template <typename OpTy>
inline match_combine_or<
match_combine_or<CastInst_match<OpTy, Instruction::ZExt>,
CastInst_match<OpTy, Instruction::SExt>>,
OpTy>
inline match_combine_or<match_combine_or<CastInst_match<OpTy, ZExtInst>,
CastInst_match<OpTy, SExtInst>>,
OpTy>
m_ZExtOrSExtOrSelf(const OpTy &Op) {
return m_CombineOr(m_ZExtOrSExt(Op), Op);
}

template <typename OpTy>
inline CastInst_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::UIToFP>(Op);
inline CastInst_match<OpTy, UIToFPInst> m_UIToFP(const OpTy &Op) {
return CastInst_match<OpTy, UIToFPInst>(Op);
}

template <typename OpTy>
inline CastInst_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::SIToFP>(Op);
inline CastInst_match<OpTy, SIToFPInst> m_SIToFP(const OpTy &Op) {
return CastInst_match<OpTy, SIToFPInst>(Op);
}

template <typename OpTy>
inline CastInst_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::FPToUI>(Op);
inline CastInst_match<OpTy, FPToUIInst> m_FPToUI(const OpTy &Op) {
return CastInst_match<OpTy, FPToUIInst>(Op);
}

template <typename OpTy>
inline CastInst_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::FPToSI>(Op);
inline CastInst_match<OpTy, FPToSIInst> m_FPToSI(const OpTy &Op) {
return CastInst_match<OpTy, FPToSIInst>(Op);
}

template <typename OpTy>
inline CastInst_match<OpTy, Instruction::FPTrunc>
m_FPTrunc(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::FPTrunc>(Op);
inline CastInst_match<OpTy, FPTruncInst> m_FPTrunc(const OpTy &Op) {
return CastInst_match<OpTy, FPTruncInst>(Op);
}

template <typename OpTy>
inline CastInst_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::FPExt>(Op);
inline CastInst_match<OpTy, FPExtInst> m_FPExt(const OpTy &Op) {
return CastInst_match<OpTy, FPExtInst>(Op);
}

//===----------------------------------------------------------------------===//
Expand Down