[llvm] r319441 - [FuzzMutate] Don't use index operands as sinks
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 07:29:16 PST 2017
Author: igor.laevsky
Date: Thu Nov 30 07:29:16 2017
New Revision: 319441
URL: http://llvm.org/viewvc/llvm-project?rev=319441&view=rev
Log:
[FuzzMutate] Don't use index operands as sinks
Differential Revision: https://reviews.llvm.org/D40396
Modified:
llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp
llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
Modified: llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp?rev=319441&r1=319440&r2=319441&view=diff
==============================================================================
--- llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp (original)
+++ llvm/trunk/lib/FuzzMutate/RandomIRBuilder.cpp Thu Nov 30 07:29:16 2017
@@ -76,12 +76,13 @@ static bool isCompatibleReplacement(cons
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:
Modified: llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp?rev=319441&r1=319440&r2=319441&view=diff
==============================================================================
--- llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp (original)
+++ llvm/trunk/unittests/FuzzMutate/RandomIRBuilderTest.cpp Thu Nov 30 07:29:16 2017
@@ -130,4 +130,38 @@ TEST(RandomIRBuilderTest, InsertValueInd
}
}
+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()));
+ }
+}
+
}
More information about the llvm-commits
mailing list