diff options
author | Igor Laevsky <igmyrj@gmail.com> | 2017-11-30 15:24:41 +0000 |
---|---|---|
committer | Igor Laevsky <igmyrj@gmail.com> | 2017-11-30 15:24:41 +0000 |
commit | faacdf8d5420282caa6e9329390cb59d765419ab (patch) | |
tree | ca4f5db068c48ce4d24457f0350e66b9e808860f /llvm/lib/FuzzMutate/RandomIRBuilder.cpp | |
parent | 444afc82c0558eaef96b0402d00490f5b9ad84cf (diff) | |
download | bcm5719-llvm-faacdf8d5420282caa6e9329390cb59d765419ab.tar.gz bcm5719-llvm-faacdf8d5420282caa6e9329390cb59d765419ab.zip |
[FuzzMutate] Don't create load as a new source if it doesn't match with the descriptor
Differential Revision: https://reviews.llvm.org/D40394
llvm-svn: 319439
Diffstat (limited to 'llvm/lib/FuzzMutate/RandomIRBuilder.cpp')
-rw-r--r-- | llvm/lib/FuzzMutate/RandomIRBuilder.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp index 42e30464b0d..3c9a35986be 100644 --- a/llvm/lib/FuzzMutate/RandomIRBuilder.cpp +++ b/llvm/lib/FuzzMutate/RandomIRBuilder.cpp @@ -45,22 +45,25 @@ Value *RandomIRBuilder::newSource(BasicBlock &BB, ArrayRef<Instruction *> Insts, // Generate some constants to choose from. auto RS = makeSampler<Value *>(Rand); RS.sample(Pred.generate(Srcs, KnownTypes)); - assert(!RS.isEmpty() && "Failed to generate sources"); // If we can find a pointer to load from, use it half the time. Value *Ptr = findPointer(BB, Insts, Srcs, Pred); - if (Ptr) - RS.sample(Ptr, RS.totalWeight()); + if (Ptr) { + // Create load from the chosen pointer + auto IP = BB.getFirstInsertionPt(); + if (auto *I = dyn_cast<Instruction>(Ptr)) + IP = ++I->getIterator(); + auto *NewLoad = new LoadInst(Ptr, "L", &*IP); - Value *Result = RS.getSelection(); - if (Result != Ptr) - return Result; + // Only sample this load if it really matches the descriptor + if (Pred.matches(Srcs, NewLoad)) + RS.sample(NewLoad, RS.totalWeight()); + else + NewLoad->eraseFromParent(); + } - // If we choose the pointer, we need to create a load. - auto IP = BB.getFirstInsertionPt(); - if (auto *I = dyn_cast<Instruction>(Ptr)) - IP = ++I->getIterator(); - return new LoadInst(Ptr, "L", &*IP); + assert(!RS.isEmpty() && "Failed to generate sources"); + return RS.getSelection(); } static bool isCompatibleReplacement(const Instruction *I, const Use &Operand, |