This is an archive of the discontinued LLVM Phabricator instance.

[MachineCopyPropagation] Handle COPY with overlapping source/dest.
ClosedPublic

Authored by efriedma on Mar 26 2018, 3:10 PM.

Details

Summary

MachineCopyPropagation::CopyPropagateBlock has a bunch of special handling for COPY instructions. This handling assumes that COPY instructions do not modify the source of the copy; this is wrong if the COPY destination overlaps the source.

To fix the bug, check explicitly for this situation, and fall back to the generic instruction handling.

This bug can't happen for most register classes because they don't have this sort of overlap, but there are a few register classes where this is possible. The testcase uses the AArch64 QQQQ register class.

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Mar 26 2018, 3:10 PM

I'm not sure I see what's wrong with removing the second COPY in either of these cases, unless the semantics of the multi-register COPY are that each component register is copied in order?

COPY in registers is sort of like memmove in memory; the value in the destination is equivalent to the value that was in the source.

If you try copyprop5 on trunk, you'll find it eliminates the second COPY, but not the first, so q28 and q29 contain the wrong value at the point of the call.

gberry accepted this revision.Mar 28 2018, 3:12 PM

I get it now. LGTM

This revision is now accepted and ready to land.Mar 28 2018, 3:12 PM
This revision was automatically updated to reflect the committed changes.