Page MenuHomePhabricator

[MemCpyOpt] Use dereferenceable pointer helper
ClosedPublic

Authored by nikic on Sun, Oct 4, 1:37 PM.

Details

Summary

The call slot optimization has some home-grown code for checking whether the destination is dereferenceable. Replace this with the generic isDereferenceableAndAlignedPointer() helper.

I'm not checking alignment here, because that is currently handled separately and may be an enforced alignment for allocas. The clean way of integrating that part would probably be to accept a callback in isDereferenceableAndAlignedPointer() for the actual isAligned check, which would then have a chance to use an enforced alignment instead.

Diff Detail

Event Timeline

nikic created this revision.Sun, Oct 4, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptSun, Oct 4, 1:37 PM
nikic requested review of this revision.Sun, Oct 4, 1:37 PM
nikic added inline comments.Sun, Oct 4, 1:47 PM
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
867

By the way, is there any existing API for this? That is, to move an instruction and its dependencies up, for trivially speculatable cases. I've seen CodeMoverUtils, but that's a very big hammer (even requiring PDT).

efriedma accepted this revision.Sun, Oct 4, 2:26 PM

LGTM

We could probably clean up the alignment handling in this pass now that the src and dest alignment of memcpy are separate.

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
817

Not really related to this patch, but is mayThrow actually the right check? Do we need willreturn instead?

This revision is now accepted and ready to land.Sun, Oct 4, 2:26 PM
efriedma added inline comments.Sun, Oct 4, 2:28 PM
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
867

I can't think of anything off the top of my head. You wouldn't usually want to speculate an arbitrary number of instructions without some cost model, anyway, and then it gets really complicated.

This revision was landed with ongoing or failed builds.Tue, Oct 6, 9:45 AM
This revision was automatically updated to reflect the committed changes.