diff options
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, |