This is an archive of the discontinued LLVM Phabricator instance.

MachineCopyPropagation: Remove the copies instead of using KILL instructions.
ClosedPublic

Authored by MatzeB on May 28 2015, 6:53 PM.

Details

Summary

For some history here see the commit messages of r199797 and r169060.

The original intent was to fix cases like:

%EAX<def> = COPY %ECX<kill>, %RAX<imp-def>
%RCX<def> = COPY %RAX<kill>

where simply removing the copies would have RCX undefined as in terms of
machine operands only the ECX part of it is defined. The machine
verifier would complain about this so 169060 changed such COPY
instructions into KILL instructions so some super-register imp-defs
would be preserved. In r199797 it was finally decided to always do this
regardless of super-register defs.

But this is wrong! Consider:
R1 = COPY R0
...
R0 = COPY R1
getting changed to:
R1 = KILL R0
...
R0 = KILL R1

It now looks like R0 dies at the first KILL and won't be alive until the
second KILL!

Apparently few people do proper liveness queries this late in the
compiler so this was not noticed. In fact I didn't manage to create a
testcase without other unrelated changes I am working on at the moment.

Anyway the fix is simple: As of r223896 the MachineVerifier allows reads
from partially defined registers, so the whole transforming COPY->KILL
thing is not necessary anymore. This patch also changes a similar (but
more benign case as the def was also always in the src list) case in the
VirtRegRewriter.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB updated this revision to Diff 26766.May 28 2015, 6:53 PM
MatzeB retitled this revision from to MachineCopyPropagation: Remove the copies instead of using KILL instructions..
MatzeB updated this object.
MatzeB edited the test plan for this revision. (Show Details)
MatzeB added reviewers: qcolombet, jmolloy.
MatzeB set the repository for this revision to rL LLVM.

I just found out about https://llvm.org/bugs/show_bug.cgi?id=18663 which can probably be fixed properly after this patch.

qcolombet accepted this revision.May 29 2015, 10:06 AM
qcolombet edited edge metadata.

LGTM.

Thanks,
-Quentin

This revision is now accepted and ready to land.May 29 2015, 10:06 AM

Add missing llvm-commits subscriber

MatzeB edited the test plan for this revision. (Show Details)May 29 2015, 10:56 AM
MatzeB edited edge metadata.
MatzeB added a subscriber: Unknown Object (MLST).
This revision was automatically updated to reflect the committed changes.