Skip to content

Commit 2950594

Browse files
authored
[PatternMatch] Use dyn_cast in CastInst_match instead of checking opcode. NFC (#79878)
Using dyn_cast allows us to use CastInst::getOperand instead of Instruction::getOperand. This is more efficient since CastInst::getOperand doesn't need to check how the operands are stored. Instruction::getOperand has to consider HungOffUses.
1 parent 547c395 commit 2950594

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,14 +1663,14 @@ template <typename Op_t, unsigned Opcode> struct CastOperator_match {
16631663
}
16641664
};
16651665

1666-
template <typename Op_t, unsigned Opcode> struct CastInst_match {
1666+
template <typename Op_t, typename Class> struct CastInst_match {
16671667
Op_t Op;
16681668

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

16711671
template <typename OpTy> bool match(OpTy *V) {
1672-
if (auto *I = dyn_cast<Instruction>(V))
1673-
return I->getOpcode() == Opcode && Op.match(I->getOperand(0));
1672+
if (auto *I = dyn_cast<Class>(V))
1673+
return Op.match(I->getOperand(0));
16741674
return false;
16751675
}
16761676
};
@@ -1698,9 +1698,8 @@ template <typename Op_t> struct NNegZExt_match {
16981698
NNegZExt_match(const Op_t &OpMatch) : Op(OpMatch) {}
16991699

17001700
template <typename OpTy> bool match(OpTy *V) {
1701-
if (auto *I = dyn_cast<Instruction>(V))
1702-
return I->getOpcode() == Instruction::ZExt && I->hasNonNeg() &&
1703-
Op.match(I->getOperand(0));
1701+
if (auto *I = dyn_cast<ZExtInst>(V))
1702+
return I->hasNonNeg() && Op.match(I->getOperand(0));
17041703
return false;
17051704
}
17061705
};
@@ -1746,14 +1745,14 @@ m_TruncOrSelf(const OpTy &Op) {
17461745

17471746
/// Matches SExt.
17481747
template <typename OpTy>
1749-
inline CastInst_match<OpTy, Instruction::SExt> m_SExt(const OpTy &Op) {
1750-
return CastInst_match<OpTy, Instruction::SExt>(Op);
1748+
inline CastInst_match<OpTy, SExtInst> m_SExt(const OpTy &Op) {
1749+
return CastInst_match<OpTy, SExtInst>(Op);
17511750
}
17521751

17531752
/// Matches ZExt.
17541753
template <typename OpTy>
1755-
inline CastInst_match<OpTy, Instruction::ZExt> m_ZExt(const OpTy &Op) {
1756-
return CastInst_match<OpTy, Instruction::ZExt>(Op);
1754+
inline CastInst_match<OpTy, ZExtInst> m_ZExt(const OpTy &Op) {
1755+
return CastInst_match<OpTy, ZExtInst>(Op);
17571756
}
17581757

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

17641763
template <typename OpTy>
1765-
inline match_combine_or<CastInst_match<OpTy, Instruction::ZExt>, OpTy>
1764+
inline match_combine_or<CastInst_match<OpTy, ZExtInst>, OpTy>
17661765
m_ZExtOrSelf(const OpTy &Op) {
17671766
return m_CombineOr(m_ZExt(Op), Op);
17681767
}
17691768

17701769
template <typename OpTy>
1771-
inline match_combine_or<CastInst_match<OpTy, Instruction::SExt>, OpTy>
1770+
inline match_combine_or<CastInst_match<OpTy, SExtInst>, OpTy>
17721771
m_SExtOrSelf(const OpTy &Op) {
17731772
return m_CombineOr(m_SExt(Op), Op);
17741773
}
17751774

17761775
/// Match either "sext" or "zext nneg".
17771776
template <typename OpTy>
1778-
inline match_combine_or<CastInst_match<OpTy, Instruction::SExt>,
1779-
NNegZExt_match<OpTy>>
1777+
inline match_combine_or<CastInst_match<OpTy, SExtInst>, NNegZExt_match<OpTy>>
17801778
m_SExtLike(const OpTy &Op) {
17811779
return m_CombineOr(m_SExt(Op), m_NNegZExt(Op));
17821780
}
17831781

17841782
template <typename OpTy>
1785-
inline match_combine_or<CastInst_match<OpTy, Instruction::ZExt>,
1786-
CastInst_match<OpTy, Instruction::SExt>>
1783+
inline match_combine_or<CastInst_match<OpTy, ZExtInst>,
1784+
CastInst_match<OpTy, SExtInst>>
17871785
m_ZExtOrSExt(const OpTy &Op) {
17881786
return m_CombineOr(m_ZExt(Op), m_SExt(Op));
17891787
}
17901788

17911789
template <typename OpTy>
1792-
inline match_combine_or<
1793-
match_combine_or<CastInst_match<OpTy, Instruction::ZExt>,
1794-
CastInst_match<OpTy, Instruction::SExt>>,
1795-
OpTy>
1790+
inline match_combine_or<match_combine_or<CastInst_match<OpTy, ZExtInst>,
1791+
CastInst_match<OpTy, SExtInst>>,
1792+
OpTy>
17961793
m_ZExtOrSExtOrSelf(const OpTy &Op) {
17971794
return m_CombineOr(m_ZExtOrSExt(Op), Op);
17981795
}
17991796

18001797
template <typename OpTy>
1801-
inline CastInst_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
1802-
return CastInst_match<OpTy, Instruction::UIToFP>(Op);
1798+
inline CastInst_match<OpTy, UIToFPInst> m_UIToFP(const OpTy &Op) {
1799+
return CastInst_match<OpTy, UIToFPInst>(Op);
18031800
}
18041801

18051802
template <typename OpTy>
1806-
inline CastInst_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
1807-
return CastInst_match<OpTy, Instruction::SIToFP>(Op);
1803+
inline CastInst_match<OpTy, SIToFPInst> m_SIToFP(const OpTy &Op) {
1804+
return CastInst_match<OpTy, SIToFPInst>(Op);
18081805
}
18091806

18101807
template <typename OpTy>
1811-
inline CastInst_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
1812-
return CastInst_match<OpTy, Instruction::FPToUI>(Op);
1808+
inline CastInst_match<OpTy, FPToUIInst> m_FPToUI(const OpTy &Op) {
1809+
return CastInst_match<OpTy, FPToUIInst>(Op);
18131810
}
18141811

18151812
template <typename OpTy>
1816-
inline CastInst_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
1817-
return CastInst_match<OpTy, Instruction::FPToSI>(Op);
1813+
inline CastInst_match<OpTy, FPToSIInst> m_FPToSI(const OpTy &Op) {
1814+
return CastInst_match<OpTy, FPToSIInst>(Op);
18181815
}
18191816

18201817
template <typename OpTy>
1821-
inline CastInst_match<OpTy, Instruction::FPTrunc>
1822-
m_FPTrunc(const OpTy &Op) {
1823-
return CastInst_match<OpTy, Instruction::FPTrunc>(Op);
1818+
inline CastInst_match<OpTy, FPTruncInst> m_FPTrunc(const OpTy &Op) {
1819+
return CastInst_match<OpTy, FPTruncInst>(Op);
18241820
}
18251821

18261822
template <typename OpTy>
1827-
inline CastInst_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
1828-
return CastInst_match<OpTy, Instruction::FPExt>(Op);
1823+
inline CastInst_match<OpTy, FPExtInst> m_FPExt(const OpTy &Op) {
1824+
return CastInst_match<OpTy, FPExtInst>(Op);
18291825
}
18301826

18311827
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)