@@ -1133,6 +1133,85 @@ TEST_F(PatternMatchTest, WithOverflowInst) {
1133
1133
EXPECT_EQ (Add, WOI);
1134
1134
}
1135
1135
1136
+ TEST_F (PatternMatchTest, IntrinsicMatcher) {
1137
+ Value *Name = IRB.CreateAlloca (IRB.getInt8Ty ());
1138
+ Value *Hash = IRB.getInt64 (0 );
1139
+ Value *Num = IRB.getInt32 (1 );
1140
+ Value *Index = IRB.getInt32 (2 );
1141
+ Value *Step = IRB.getInt64 (3 );
1142
+
1143
+ Value *Ops[] = {Name, Hash, Num, Index, Step};
1144
+ Module *M = BB->getParent ()->getParent ();
1145
+ Function *TheFn =
1146
+ Intrinsic::getDeclaration (M, Intrinsic::instrprof_increment_step);
1147
+
1148
+ Value *Intrinsic5 = CallInst::Create (TheFn, Ops, " " , BB);
1149
+
1150
+ // Match without capturing.
1151
+ EXPECT_TRUE (match (
1152
+ Intrinsic5, m_Intrinsic<Intrinsic::instrprof_increment_step>(
1153
+ m_Value (), m_Value (), m_Value (), m_Value (), m_Value ())));
1154
+ EXPECT_FALSE (match (
1155
+ Intrinsic5, m_Intrinsic<Intrinsic::memmove >(
1156
+ m_Value (), m_Value (), m_Value (), m_Value (), m_Value ())));
1157
+
1158
+ // Match with capturing.
1159
+ Value *Arg1 = nullptr ;
1160
+ Value *Arg2 = nullptr ;
1161
+ Value *Arg3 = nullptr ;
1162
+ Value *Arg4 = nullptr ;
1163
+ Value *Arg5 = nullptr ;
1164
+ EXPECT_TRUE (
1165
+ match (Intrinsic5, m_Intrinsic<Intrinsic::instrprof_increment_step>(
1166
+ m_Value (Arg1), m_Value (Arg2), m_Value (Arg3),
1167
+ m_Value (Arg4), m_Value (Arg5))));
1168
+ EXPECT_EQ (Arg1, Name);
1169
+ EXPECT_EQ (Arg2, Hash);
1170
+ EXPECT_EQ (Arg3, Num);
1171
+ EXPECT_EQ (Arg4, Index);
1172
+ EXPECT_EQ (Arg5, Step);
1173
+
1174
+ // Match specific second argument.
1175
+ EXPECT_TRUE (
1176
+ match (Intrinsic5,
1177
+ m_Intrinsic<Intrinsic::instrprof_increment_step>(
1178
+ m_Value (), m_SpecificInt (0 ), m_Value (), m_Value (), m_Value ())));
1179
+ EXPECT_FALSE (
1180
+ match (Intrinsic5, m_Intrinsic<Intrinsic::instrprof_increment_step>(
1181
+ m_Value (), m_SpecificInt (10 ), m_Value (), m_Value (),
1182
+ m_Value ())));
1183
+
1184
+ // Match specific third argument.
1185
+ EXPECT_TRUE (
1186
+ match (Intrinsic5,
1187
+ m_Intrinsic<Intrinsic::instrprof_increment_step>(
1188
+ m_Value (), m_Value (), m_SpecificInt (1 ), m_Value (), m_Value ())));
1189
+ EXPECT_FALSE (
1190
+ match (Intrinsic5, m_Intrinsic<Intrinsic::instrprof_increment_step>(
1191
+ m_Value (), m_Value (), m_SpecificInt (10 ), m_Value (),
1192
+ m_Value ())));
1193
+
1194
+ // Match specific fourth argument.
1195
+ EXPECT_TRUE (
1196
+ match (Intrinsic5,
1197
+ m_Intrinsic<Intrinsic::instrprof_increment_step>(
1198
+ m_Value (), m_Value (), m_Value (), m_SpecificInt (2 ), m_Value ())));
1199
+ EXPECT_FALSE (
1200
+ match (Intrinsic5, m_Intrinsic<Intrinsic::instrprof_increment_step>(
1201
+ m_Value (), m_Value (), m_Value (), m_SpecificInt (10 ),
1202
+ m_Value ())));
1203
+
1204
+ // Match specific fifth argument.
1205
+ EXPECT_TRUE (
1206
+ match (Intrinsic5,
1207
+ m_Intrinsic<Intrinsic::instrprof_increment_step>(
1208
+ m_Value (), m_Value (), m_Value (), m_Value (), m_SpecificInt (3 ))));
1209
+ EXPECT_FALSE (
1210
+ match (Intrinsic5, m_Intrinsic<Intrinsic::instrprof_increment_step>(
1211
+ m_Value (), m_Value (), m_Value (), m_Value (),
1212
+ m_SpecificInt (10 ))));
1213
+ }
1214
+
1136
1215
template <typename T> struct MutableConstTest : PatternMatchTest { };
1137
1216
1138
1217
typedef ::testing::Types<std::tuple<Value*, Instruction*>,
0 commit comments