Skip to content

[PatternMatch] Refactor m_SpecificInt to avoid constructing APInt. NFC. #86259

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
Mar 26, 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
35 changes: 25 additions & 10 deletions llvm/include/llvm/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,9 @@ struct bind_const_intval_ty {
/// Match a specified integer value or vector of all elements of that
/// value.
template <bool AllowUndefs> struct specific_intval {
APInt Val;
const APInt &Val;

specific_intval(APInt V) : Val(std::move(V)) {}
specific_intval(const APInt &V) : Val(V) {}

template <typename ITy> bool match(ITy *V) {
const auto *CI = dyn_cast<ConstantInt>(V);
Expand All @@ -898,22 +898,37 @@ template <bool AllowUndefs> struct specific_intval {
}
};

template <bool AllowUndefs> struct specific_intval64 {
uint64_t Val;

specific_intval64(uint64_t V) : Val(V) {}

template <typename ITy> bool match(ITy *V) {
const auto *CI = dyn_cast<ConstantInt>(V);
if (!CI && V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowUndefs));

return CI && CI->getValue() == Val;
}
};

/// Match a specific integer value or vector with all elements equal to
/// the value.
inline specific_intval<false> m_SpecificInt(APInt V) {
return specific_intval<false>(std::move(V));
inline specific_intval<false> m_SpecificInt(const APInt &V) {
return specific_intval<false>(V);
}

inline specific_intval<false> m_SpecificInt(uint64_t V) {
return m_SpecificInt(APInt(64, V));
inline specific_intval64<false> m_SpecificInt(uint64_t V) {
return specific_intval64<false>(V);
}

inline specific_intval<true> m_SpecificIntAllowUndef(APInt V) {
return specific_intval<true>(std::move(V));
inline specific_intval<true> m_SpecificIntAllowUndef(const APInt &V) {
return specific_intval<true>(V);
}

inline specific_intval<true> m_SpecificIntAllowUndef(uint64_t V) {
return m_SpecificIntAllowUndef(APInt(64, V));
inline specific_intval64<true> m_SpecificIntAllowUndef(uint64_t V) {
return specific_intval64<true>(V);
}

/// Match a ConstantInt and bind to its value. This does not match
Expand Down