mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[PatternMatch] Add single index InsertValue matcher.
This patch adds a new matcher for single index InsertValue instructions, similar to the existing matcher for ExtractValue. Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D91352
This commit is contained in:
parent
7dc590a5ce
commit
f7e32458e4
@ -2298,6 +2298,29 @@ inline ExtractValue_match<Ind, Val_t> m_ExtractValue(const Val_t &V) {
|
||||
return ExtractValue_match<Ind, Val_t>(V);
|
||||
}
|
||||
|
||||
/// Matcher for a single index InsertValue instruction.
|
||||
template <int Ind, typename T0, typename T1> struct InsertValue_match {
|
||||
T0 Op0;
|
||||
T1 Op1;
|
||||
|
||||
InsertValue_match(const T0 &Op0, const T1 &Op1) : Op0(Op0), Op1(Op1) {}
|
||||
|
||||
template <typename OpTy> bool match(OpTy *V) {
|
||||
if (auto *I = dyn_cast<InsertValueInst>(V)) {
|
||||
return Op0.match(I->getOperand(0)) && Op1.match(I->getOperand(1)) &&
|
||||
I->getNumIndices() == 1 && Ind == I->getIndices()[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/// Matches a single index InsertValue instruction.
|
||||
template <int Ind, typename Val_t, typename Elt_t>
|
||||
inline InsertValue_match<Ind, Val_t, Elt_t> m_InsertValue(const Val_t &Val,
|
||||
const Elt_t &Elt) {
|
||||
return InsertValue_match<Ind, Val_t, Elt_t>(Val, Elt);
|
||||
}
|
||||
|
||||
/// Matches patterns for `vscale`. This can either be a call to `llvm.vscale` or
|
||||
/// the constant expression
|
||||
/// `ptrtoint(gep <vscale x 1 x i8>, <vscale x 1 x i8>* null, i32 1>`
|
||||
|
@ -1581,6 +1581,27 @@ TEST_F(PatternMatchTest, ConstantPredicateType) {
|
||||
match(CF32NaNWithUndef, cstfp_pred_ty<always_false_pred<APFloat>>()));
|
||||
}
|
||||
|
||||
TEST_F(PatternMatchTest, InsertValue) {
|
||||
Type *StructTy = StructType::create(IRB.getContext(),
|
||||
{IRB.getInt32Ty(), IRB.getInt64Ty()});
|
||||
Value *Ins0 =
|
||||
IRB.CreateInsertValue(UndefValue::get(StructTy), IRB.getInt32(20), 0);
|
||||
Value *Ins1 = IRB.CreateInsertValue(Ins0, IRB.getInt64(90), 1);
|
||||
|
||||
EXPECT_TRUE(match(Ins0, m_InsertValue<0>(m_Value(), m_Value())));
|
||||
EXPECT_FALSE(match(Ins0, m_InsertValue<1>(m_Value(), m_Value())));
|
||||
EXPECT_FALSE(match(Ins1, m_InsertValue<0>(m_Value(), m_Value())));
|
||||
EXPECT_TRUE(match(Ins1, m_InsertValue<1>(m_Value(), m_Value())));
|
||||
|
||||
EXPECT_TRUE(match(Ins0, m_InsertValue<0>(m_Undef(), m_SpecificInt(20))));
|
||||
EXPECT_FALSE(match(Ins0, m_InsertValue<0>(m_Undef(), m_SpecificInt(0))));
|
||||
|
||||
EXPECT_TRUE(
|
||||
match(Ins1, m_InsertValue<1>(m_InsertValue<0>(m_Value(), m_Value()),
|
||||
m_SpecificInt(90))));
|
||||
EXPECT_FALSE(match(IRB.getInt64(99), m_InsertValue<0>(m_Value(), m_Value())));
|
||||
}
|
||||
|
||||
template <typename T> struct MutableConstTest : PatternMatchTest { };
|
||||
|
||||
typedef ::testing::Types<std::tuple<Value*, Instruction*>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user