[PATCH] D91352: [PatternMatch] Add single index InsertValue matcher.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 13:27:43 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1f6f300404a: [PatternMatch] Add single index InsertValue matcher. (authored by fhahn).
Changed prior to commit:
https://reviews.llvm.org/D91352?vs=304822&id=304957#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91352/new/
https://reviews.llvm.org/D91352
Files:
llvm/include/llvm/IR/PatternMatch.h
llvm/unittests/IR/PatternMatch.cpp
Index: llvm/unittests/IR/PatternMatch.cpp
===================================================================
--- llvm/unittests/IR/PatternMatch.cpp
+++ llvm/unittests/IR/PatternMatch.cpp
@@ -1581,6 +1581,27 @@
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*>,
Index: llvm/include/llvm/IR/PatternMatch.h
===================================================================
--- llvm/include/llvm/IR/PatternMatch.h
+++ llvm/include/llvm/IR/PatternMatch.h
@@ -2298,6 +2298,29 @@
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>`
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91352.304957.patch
Type: text/x-patch
Size: 2724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201112/7c25059a/attachment.bin>
More information about the llvm-commits
mailing list