This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] set dereferenceable flag when expanding memcpy/memmove
ClosedPublic

Authored by inouehrs on Jun 21 2017, 11:45 AM.

Details

Summary

When SelectionDAG expands memcpy (or memmove) call into a sequence of load and store instructions, it disregards dereferenceable flag even the source pointer is known to be dereferenceable.
This results in an assertion failure if SelectionDAG commonizes a load instruction generated for memcpy with another load instruction for the source pointer.
This patch makes SelectionDAG to set the dereferenceable flag for the load instructions properly to avoid the assertion failure.

Diff Detail

Repository
rL LLVM

Event Timeline

inouehrs created this revision.Jun 21 2017, 11:45 AM
hfinkel added inline comments.
lib/CodeGen/MachineInstr.cpp
576 ↗(On Diff #103428)

Creating temporary instructions in helper functions is something we try very hard not to do. Please don't do it here.

The underlying isDereferenceableAndAlignedPointer implementation function in lib/Analysis/Loads.cpp actually takes a size. Feel free to expose an interface directly to that functionality if necessary.

inouehrs updated this revision to Diff 103596.Jun 22 2017, 9:56 AM
inouehrs added a reviewer: hfinkel.

updated the implementation to avoid creating temporary instructions

inouehrs added inline comments.Jun 22 2017, 9:59 AM
lib/CodeGen/MachineInstr.cpp
576 ↗(On Diff #103428)

I added an interface to pass size as a parameter in isDereferenceableAndAlignedPointer and eliminated the temporary instructions in the helper.
Thank you for the suggestion.

inouehrs updated this revision to Diff 103696.Jun 23 2017, 1:31 AM
inouehrs edited the summary of this revision. (Show Details)
  • added a test case extracted from a large application which causes an assertion failure
inouehrs updated this revision to Diff 103699.Jun 23 2017, 1:51 AM

minor touch up in the test case

hfinkel edited edge metadata.Jun 23 2017, 6:46 PM

Please rebase after r306193 and post the patch with full context.

hfinkel accepted this revision.Jun 24 2017, 6:55 AM

LGTM

This revision is now accepted and ready to land.Jun 24 2017, 6:55 AM
This revision was automatically updated to reflect the committed changes.