Skip to content

Commit ee9220c

Browse files
committed
[PatternMatch] Don't try to match sext/zext const exprs (NFCI)
1 parent 48be81e commit ee9220c

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,10 +1576,10 @@ m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) {
15761576
// Matchers for CastInst classes
15771577
//
15781578

1579-
template <typename Op_t, unsigned Opcode> struct CastClass_match {
1579+
template <typename Op_t, unsigned Opcode> struct CastOperator_match {
15801580
Op_t Op;
15811581

1582-
CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
1582+
CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {}
15831583

15841584
template <typename OpTy> bool match(OpTy *V) {
15851585
if (auto *O = dyn_cast<Operator>(V))
@@ -1588,6 +1588,18 @@ template <typename Op_t, unsigned Opcode> struct CastClass_match {
15881588
}
15891589
};
15901590

1591+
template <typename Op_t, unsigned Opcode> struct CastInst_match {
1592+
Op_t Op;
1593+
1594+
CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {}
1595+
1596+
template <typename OpTy> bool match(OpTy *V) {
1597+
if (auto *I = dyn_cast<Instruction>(V))
1598+
return I->getOpcode() == Opcode && Op.match(I->getOperand(0));
1599+
return false;
1600+
}
1601+
};
1602+
15911603
template <typename Op_t> struct PtrToIntSameSize_match {
15921604
const DataLayout &DL;
15931605
Op_t Op;
@@ -1607,14 +1619,16 @@ template <typename Op_t> struct PtrToIntSameSize_match {
16071619

16081620
/// Matches BitCast.
16091621
template <typename OpTy>
1610-
inline CastClass_match<OpTy, Instruction::BitCast> m_BitCast(const OpTy &Op) {
1611-
return CastClass_match<OpTy, Instruction::BitCast>(Op);
1622+
inline CastOperator_match<OpTy, Instruction::BitCast>
1623+
m_BitCast(const OpTy &Op) {
1624+
return CastOperator_match<OpTy, Instruction::BitCast>(Op);
16121625
}
16131626

16141627
/// Matches PtrToInt.
16151628
template <typename OpTy>
1616-
inline CastClass_match<OpTy, Instruction::PtrToInt> m_PtrToInt(const OpTy &Op) {
1617-
return CastClass_match<OpTy, Instruction::PtrToInt>(Op);
1629+
inline CastOperator_match<OpTy, Instruction::PtrToInt>
1630+
m_PtrToInt(const OpTy &Op) {
1631+
return CastOperator_match<OpTy, Instruction::PtrToInt>(Op);
16181632
}
16191633

16201634
template <typename OpTy>
@@ -1625,90 +1639,92 @@ inline PtrToIntSameSize_match<OpTy> m_PtrToIntSameSize(const DataLayout &DL,
16251639

16261640
/// Matches IntToPtr.
16271641
template <typename OpTy>
1628-
inline CastClass_match<OpTy, Instruction::IntToPtr> m_IntToPtr(const OpTy &Op) {
1629-
return CastClass_match<OpTy, Instruction::IntToPtr>(Op);
1642+
inline CastOperator_match<OpTy, Instruction::IntToPtr>
1643+
m_IntToPtr(const OpTy &Op) {
1644+
return CastOperator_match<OpTy, Instruction::IntToPtr>(Op);
16301645
}
16311646

16321647
/// Matches Trunc.
16331648
template <typename OpTy>
1634-
inline CastClass_match<OpTy, Instruction::Trunc> m_Trunc(const OpTy &Op) {
1635-
return CastClass_match<OpTy, Instruction::Trunc>(Op);
1649+
inline CastOperator_match<OpTy, Instruction::Trunc> m_Trunc(const OpTy &Op) {
1650+
return CastOperator_match<OpTy, Instruction::Trunc>(Op);
16361651
}
16371652

16381653
template <typename OpTy>
1639-
inline match_combine_or<CastClass_match<OpTy, Instruction::Trunc>, OpTy>
1654+
inline match_combine_or<CastOperator_match<OpTy, Instruction::Trunc>, OpTy>
16401655
m_TruncOrSelf(const OpTy &Op) {
16411656
return m_CombineOr(m_Trunc(Op), Op);
16421657
}
16431658

16441659
/// Matches SExt.
16451660
template <typename OpTy>
1646-
inline CastClass_match<OpTy, Instruction::SExt> m_SExt(const OpTy &Op) {
1647-
return CastClass_match<OpTy, Instruction::SExt>(Op);
1661+
inline CastInst_match<OpTy, Instruction::SExt> m_SExt(const OpTy &Op) {
1662+
return CastInst_match<OpTy, Instruction::SExt>(Op);
16481663
}
16491664

16501665
/// Matches ZExt.
16511666
template <typename OpTy>
1652-
inline CastClass_match<OpTy, Instruction::ZExt> m_ZExt(const OpTy &Op) {
1653-
return CastClass_match<OpTy, Instruction::ZExt>(Op);
1667+
inline CastInst_match<OpTy, Instruction::ZExt> m_ZExt(const OpTy &Op) {
1668+
return CastInst_match<OpTy, Instruction::ZExt>(Op);
16541669
}
16551670

16561671
template <typename OpTy>
1657-
inline match_combine_or<CastClass_match<OpTy, Instruction::ZExt>, OpTy>
1672+
inline match_combine_or<CastInst_match<OpTy, Instruction::ZExt>, OpTy>
16581673
m_ZExtOrSelf(const OpTy &Op) {
16591674
return m_CombineOr(m_ZExt(Op), Op);
16601675
}
16611676

16621677
template <typename OpTy>
1663-
inline match_combine_or<CastClass_match<OpTy, Instruction::SExt>, OpTy>
1678+
inline match_combine_or<CastInst_match<OpTy, Instruction::SExt>, OpTy>
16641679
m_SExtOrSelf(const OpTy &Op) {
16651680
return m_CombineOr(m_SExt(Op), Op);
16661681
}
16671682

16681683
template <typename OpTy>
1669-
inline match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
1670-
CastClass_match<OpTy, Instruction::SExt>>
1684+
inline match_combine_or<CastInst_match<OpTy, Instruction::ZExt>,
1685+
CastInst_match<OpTy, Instruction::SExt>>
16711686
m_ZExtOrSExt(const OpTy &Op) {
16721687
return m_CombineOr(m_ZExt(Op), m_SExt(Op));
16731688
}
16741689

16751690
template <typename OpTy>
16761691
inline match_combine_or<
1677-
match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
1678-
CastClass_match<OpTy, Instruction::SExt>>,
1692+
match_combine_or<CastInst_match<OpTy, Instruction::ZExt>,
1693+
CastInst_match<OpTy, Instruction::SExt>>,
16791694
OpTy>
16801695
m_ZExtOrSExtOrSelf(const OpTy &Op) {
16811696
return m_CombineOr(m_ZExtOrSExt(Op), Op);
16821697
}
16831698

16841699
template <typename OpTy>
1685-
inline CastClass_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
1686-
return CastClass_match<OpTy, Instruction::UIToFP>(Op);
1700+
inline CastOperator_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
1701+
return CastOperator_match<OpTy, Instruction::UIToFP>(Op);
16871702
}
16881703

16891704
template <typename OpTy>
1690-
inline CastClass_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
1691-
return CastClass_match<OpTy, Instruction::SIToFP>(Op);
1705+
inline CastOperator_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
1706+
return CastOperator_match<OpTy, Instruction::SIToFP>(Op);
16921707
}
16931708

16941709
template <typename OpTy>
1695-
inline CastClass_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
1696-
return CastClass_match<OpTy, Instruction::FPToUI>(Op);
1710+
inline CastOperator_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
1711+
return CastOperator_match<OpTy, Instruction::FPToUI>(Op);
16971712
}
16981713

16991714
template <typename OpTy>
1700-
inline CastClass_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
1701-
return CastClass_match<OpTy, Instruction::FPToSI>(Op);
1715+
inline CastOperator_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
1716+
return CastOperator_match<OpTy, Instruction::FPToSI>(Op);
17021717
}
17031718

17041719
template <typename OpTy>
1705-
inline CastClass_match<OpTy, Instruction::FPTrunc> m_FPTrunc(const OpTy &Op) {
1706-
return CastClass_match<OpTy, Instruction::FPTrunc>(Op);
1720+
inline CastOperator_match<OpTy, Instruction::FPTrunc>
1721+
m_FPTrunc(const OpTy &Op) {
1722+
return CastOperator_match<OpTy, Instruction::FPTrunc>(Op);
17071723
}
17081724

17091725
template <typename OpTy>
1710-
inline CastClass_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
1711-
return CastClass_match<OpTy, Instruction::FPExt>(Op);
1726+
inline CastOperator_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
1727+
return CastOperator_match<OpTy, Instruction::FPExt>(Op);
17121728
}
17131729

17141730
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)