MachineCopyPropagation has special logic for removing COPY instructions. It will...
authorJames Molloy <james.molloy@arm.com>
Wed, 22 Jan 2014 09:12:27 +0000 (09:12 +0000)
committerJames Molloy <james.molloy@arm.com>
Wed, 22 Jan 2014 09:12:27 +0000 (09:12 +0000)
commitbb96dfcf4f58ae7152f4be92254a0bb1c0995e6d
tree2071bd755d83d16b6dec25fa380b63380f2befca
parent290ad96e86969b72d46d3444a41030d66f82b60e
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199797 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/MachineCopyPropagation.cpp
test/CodeGen/X86/machine-cp.ll