[PATCH] Fix MachineCopyPropagation with subregs

James Molloy james.molloy at arm.com
Tue Jan 21 10:30:42 PST 2014


Hi Tim (and other reviewers),

 

MachineCopyPropagation has special logic for removing COPY instructions. It
will remove plain COPYs using eraseFromParent(), but if the COPY has
imp-defs/imp-uses it will convert it to a KILL, to keep the imp-def around.

 

This actually totally breaks and causes the machine verifier to cry in
several cases, one of which being:

 

%RAX<def> = COPY %RCX<kill>

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

 

These subregister copies are together identified as noops, so are both
removed. However, the second one as it has an imp-use gets converted into a
kill:

 

%ECX<def> = KILL %EAX<kill>, %RAX<imp-use,kill>

 

As the original COPY has been removed, the verifier goes into tears at the
use of undefined EAX and RAX.

 

There are several hacky solutions to this hacky problem (which is all to do
with imp-use/def weirdnesses), but the least hacky I've come up with is to
*always* remove COPYs by converting to KILLs. KILLs are no-ops to the code
generator so the generated code doesn't change (which is why they were
partially used in the first place), but using them also keeps the def/use
and imp-def/imp-use chains alive:

 

%RAX<def> = KILL %RCX<kill>

%ECX<def> = KILL %EAX<kill>, %RAX<imp-use,kill>

 

The patch passes all test cases including the ones that check the removal of
MOVs in this circumstance, along with an extra test I added to check
subregister behaviour (which made the machine verifier fall over before my
patch).

 

The patch also adds some DEBUG() statements because the file hadn't got any.

 

Please review!

 

Cheers,

 

James

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140121/b5e1209a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mcp-removecopy.diff
Type: application/octet-stream
Size: 4345 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140121/b5e1209a/attachment.obj>


More information about the llvm-commits mailing list