[PATCH] [MachineCopyPropagation] Incorrect COPY removal in AArch64 backend

Hao Liu Hao.Liu at arm.com
Tue Mar 10 20:01:55 PDT 2015


Hi jmolloy, Jiangning,

This bug is happened in AArch64 backend when there are machine instruction sequences as follows:
     (a)   %Q5_Q6<def> = COPY %Q2_Q3
     (b)   %D5<def> =
     (c)   %D3<def> =
     (d)   %D3<def> = COPY %D6              // Incorrectly removed in MachineCopyPropagation
     (e)   use of %D3

The MachineCopyPropagation uses a map called AvailCopyMap to store the available COPY instructions of specific registers. The situations for executing the above sequences are as follows:
(1) After visiting instruction (a), all sub registers of Q5_Q6 are mapped to (a) in AvailCopyMap:
       Q5_Q6  - (a)
       Q5         - (a)
       D5         - (a)
       Q6         - (a)
       D6         - (a)
(2) After visiting instruction (b), as register D5 is redefined, all registers aliasing to D5 will be cleared in the AvailCopyMap. Then the Map is like:
       D6         - (a)
       Q6         - (a)
(3) When visiting instruction (c), D3 is redefined. This pass tries to remove all COPYs related to instruction (a). But such removal logic is as follows:
        if (AvailCopyMap.erase(MappedDef)) {
          for (MCSubRegIterator SR(MappedDef, TRI); SR.isValid(); ++SR)
            AvailCopyMap.erase(*SR);
        }
The MappedDef is register Q5_Q6, as it has already been removed in step (2), the for loop will never be executed. As a result, the AvailCopyMap is kept the same. We still have
       D6         - (a)
       Q6         - (a)
(4) When visiting instruction (d), it find an available COPY in the Map and remove (d).
(5) As D3 is not as expected, the test will have an incorrect result.

This fix is to make sure we remove all related COPYs in the Map in step (3). So we just need to remove the if statement.
The test case is a bit complex, as we need the specific instruction sequences to reproduce this bug.

Ask for code review.

Thanks,
-Hao

http://reviews.llvm.org/D8242

Files:
  lib/CodeGen/MachineCopyPropagation.cpp
  test/CodeGen/AArch64/machine-copy-prop.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8242.21672.patch
Type: text/x-patch
Size: 6171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150311/13ebebab/attachment.bin>


More information about the llvm-commits mailing list