This is an archive of the discontinued LLVM Phabricator instance.

[MemorySSA] Invoke the right getModRefInfo check in `instructionClobbersQuery` when UseLoc is passed.
AcceptedPublic

Authored by bryant on Nov 14 2016, 10:59 PM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

bryant updated this revision to Diff 77946.Nov 14 2016, 10:59 PM
bryant retitled this revision from to [MemorySSA] Invoke the right getModRefInfo check in `instructionClobbersQuery` when UseLoc is passed..
bryant updated this object.
bryant set the repository for this revision to rL LLVM.
bryant added a subscriber: llvm-commits.
dberlin accepted this revision.Nov 15 2016, 1:33 PM
dberlin edited edge metadata.

This looks right until we clean up getModRefInfo's interface :P

This revision is now accepted and ready to land.Nov 15 2016, 1:33 PM

Actually, can you please add a test for this before you commit?
You can use -print-memoryssa -analyze to get it to dump memoryssa.
If you need specific API calls, please add to the unit tests for MemorySSA.

I'm having trouble getting -analyze to work:

16:58:24 ~/3rd/llvm/test> opt -print-memoryssa -analyze < Transforms/Util/MemorySSA/precision-call-clobbers.ll
... # stuff
Printing analysis 'Memory SSA Printer' for function 'f':
Pass::print not implemented for pass: 'Memory SSA Printer'!

If the goal is to run FileCheck on the MemorySSA debug output, shouldn't -print-memoryssa alone be sufficient?

bryant updated this revision to Diff 79016.Nov 22 2016, 7:23 PM
bryant edited edge metadata.

Added clobber tests.