Calls to instructionClobbersQuery are meant to answer two kinds of queries:
Given two memory instructions X and Y,
- Does X clobber Y?
- Does X clobber Y with respect to a MemoryLocation UseLoc?
For queries of the first kind, a null MemoryLocation is passed, and it makes
sense for getModRefInfo(Instruction *, ImmutableCallSite) to be called.
For the second kind, however, UseLoc would be a non-null and the above call to
getModRefInfo would be unnecessarily conservative; it would be sufficient to
check getModRefInfo(Instruction *, const MemoryLocation &).
An example:
call void @llvm.memcpy(i8* %dest, i8* %src, i64 128, ...) ; MemoryDef *M0 call void @llvm.memcpy(i8* %dest, i8* %src, i64 128, ...) ; MemoryDef *M1
The call
instructionClobbersQuery(M0, MemoryLocation::getForSource(M1->getMemoryInst()), M1->getMemoryInst(), AA)
would return true -- that M0 does clobber M1's source. But this can't possibly
be the case since overlapping memcpy operands are UB.