Skip to content

Commit 89a2a47

Browse files
committed
[InstCombine] Add m_SpecificIntAllowUndef pattern matcher
m_SpecificInt doesn't accept undef elements in a vector splat value - tweak specific_intval to optionally allow undefs and add the m_SpecificIntAllowUndef variants. Allows us to remove the m_APIntAllowUndef + comparison hack inside matchFunnelShift
1 parent 5502bd6 commit 89a2a47

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ struct bind_const_intval_ty {
705705

706706
/// Match a specified integer value or vector of all elements of that
707707
/// value.
708+
template <bool AllowUndefs>
708709
struct specific_intval {
709710
APInt Val;
710711

@@ -714,22 +715,30 @@ struct specific_intval {
714715
const auto *CI = dyn_cast<ConstantInt>(V);
715716
if (!CI && V->getType()->isVectorTy())
716717
if (const auto *C = dyn_cast<Constant>(V))
717-
CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
718+
CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowUndefs));
718719

719720
return CI && APInt::isSameValue(CI->getValue(), Val);
720721
}
721722
};
722723

723724
/// Match a specific integer value or vector with all elements equal to
724725
/// the value.
725-
inline specific_intval m_SpecificInt(APInt V) {
726-
return specific_intval(std::move(V));
726+
inline specific_intval<false> m_SpecificInt(APInt V) {
727+
return specific_intval<false>(std::move(V));
727728
}
728729

729-
inline specific_intval m_SpecificInt(uint64_t V) {
730+
inline specific_intval<false> m_SpecificInt(uint64_t V) {
730731
return m_SpecificInt(APInt(64, V));
731732
}
732733

734+
inline specific_intval<true> m_SpecificIntAllowUndef(APInt V) {
735+
return specific_intval<true>(std::move(V));
736+
}
737+
738+
inline specific_intval<true> m_SpecificIntAllowUndef(uint64_t V) {
739+
return m_SpecificIntAllowUndef(APInt(64, V));
740+
}
741+
733742
/// Match a ConstantInt and bind to its value. This does not match
734743
/// ConstantInts wider than 64-bits.
735744
inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; }

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,13 +2090,11 @@ static Instruction *matchFunnelShift(Instruction &Or, InstCombinerImpl &IC) {
20902090
if (LI->ult(Width) && RI->ult(Width) && (*LI + *RI) == Width)
20912091
return ConstantInt::get(L->getType(), *LI);
20922092

2093-
const APInt *SumC;
20942093
Constant *LC, *RC;
20952094
if (match(L, m_Constant(LC)) && match(R, m_Constant(RC)) &&
20962095
match(L, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) &&
20972096
match(R, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) &&
2098-
match(ConstantExpr::getAdd(LC, RC), m_APIntAllowUndef(SumC)) &&
2099-
*SumC == Width)
2097+
match(ConstantExpr::getAdd(LC, RC), m_SpecificIntAllowUndef(Width)))
21002098
return ConstantExpr::mergeUndefsWith(LC, RC);
21012099

21022100
// (shl ShVal, X) | (lshr ShVal, (Width - x)) iff X < Width.

0 commit comments

Comments
 (0)