[PATCH] D40396: [FuzzMutate] Don't use index operands as sinks
Igor Laevsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 23 08:16:33 PST 2017
igor-laevsky created this revision.
This fixes typo in the sink generator. We can't use index operands as sinks from the arbitrary instructions. This is actually two problems: shufflevector was missing from the switch case, and ">" was used instead of ">=". I believe this check can be made less conservative, but I figured it's better to be correct for now.
https://reviews.llvm.org/D40396
Files:
lib/FuzzMutate/RandomIRBuilder.cpp
unittests/FuzzMutate/RandomIRBuilderTest.cpp
Index: unittests/FuzzMutate/RandomIRBuilderTest.cpp
===================================================================
--- unittests/FuzzMutate/RandomIRBuilderTest.cpp
+++ unittests/FuzzMutate/RandomIRBuilderTest.cpp
@@ -130,4 +130,38 @@
}
}
+TEST(RandomIRBuilderTest, ShuffleVectorSink) {
+ // Check that we will never use shuffle vector mask as a sink form the
+ // unrelated operation.
+
+ LLVMContext Ctx;
+ const char *SourceCode =
+ "define void @test(<4 x i32> %a) {\n"
+ " %S1 = shufflevector <4 x i32> %a, <4 x i32> %a, <4 x i32> undef\n"
+ " %S2 = shufflevector <4 x i32> %a, <4 x i32> %a, <4 x i32> undef\n"
+ " ret void\n"
+ "}";
+ auto M = parseAssembly(SourceCode, Ctx);
+
+ fuzzerop::OpDescriptor IVDescr = fuzzerop::insertValueDescriptor(1);
+
+ RandomIRBuilder IB(Seed, {});
+
+ // Get first basic block of the first function
+ Function &F = *M->begin();
+ BasicBlock &BB = *F.begin();
+
+ // Source is %S1
+ Instruction *Source = &*BB.begin();
+ // Sink is %S2
+ SmallVector<Instruction *, 1> Sinks = {&*std::next(BB.begin())};
+
+ // Loop to account for random decisions
+ for (int i = 0; i < 10; ++i) {
+ // Try to connect S1 to S2. We should always create new sink.
+ IB.connectToSink(BB, Sinks, Source);
+ ASSERT_TRUE(!verifyModule(*M, &errs()));
+ }
+}
+
}
Index: lib/FuzzMutate/RandomIRBuilder.cpp
===================================================================
--- lib/FuzzMutate/RandomIRBuilder.cpp
+++ lib/FuzzMutate/RandomIRBuilder.cpp
@@ -76,12 +76,13 @@
case Instruction::ExtractValue:
// TODO: We could potentially validate these, but for now just leave indices
// alone.
- if (Operand.getOperandNo() > 1)
+ if (Operand.getOperandNo() >= 1)
return false;
break;
case Instruction::InsertValue:
case Instruction::InsertElement:
- if (Operand.getOperandNo() > 2)
+ case Instruction::ShuffleVector:
+ if (Operand.getOperandNo() >= 2)
return false;
break;
default:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40396.124092.patch
Type: text/x-patch
Size: 2016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171123/70efc9f8/attachment.bin>
More information about the llvm-commits
mailing list