[llvm] r328851 - [MachineCopyPropagation] Handle COPY with overlapping source/dest.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 29 17:56:03 PDT 2018


Author: efriedma
Date: Thu Mar 29 17:56:03 2018
New Revision: 328851

URL: http://llvm.org/viewvc/llvm-project?rev=328851&view=rev
Log:
[MachineCopyPropagation] Handle COPY with overlapping source/dest.

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.

Differential Revision: https://reviews.llvm.org/D44911


Modified:
    llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp
    llvm/trunk/test/CodeGen/AArch64/machine-dead-copy.mir

Modified: llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp?rev=328851&r1=328850&r2=328851&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineCopyPropagation.cpp Thu Mar 29 17:56:03 2018
@@ -399,7 +399,9 @@ void MachineCopyPropagation::CopyPropaga
     MachineInstr *MI = &*I;
     ++I;
 
-    if (MI->isCopy()) {
+    // Analyze copies (which don't overlap themselves).
+    if (MI->isCopy() && !TRI->regsOverlap(MI->getOperand(0).getReg(),
+                                          MI->getOperand(1).getReg())) {
       unsigned Def = MI->getOperand(0).getReg();
       unsigned Src = MI->getOperand(1).getReg();
 

Modified: llvm/trunk/test/CodeGen/AArch64/machine-dead-copy.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/machine-dead-copy.mir?rev=328851&r1=328850&r2=328851&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/machine-dead-copy.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/machine-dead-copy.mir Thu Mar 29 17:56:03 2018
@@ -6,6 +6,8 @@
   define i32 @copyprop2(i32 %a, i32 %b) { ret i32 %a }
   define i32 @copyprop3(i32 %a, i32 %b) { ret i32 %a }
   define i32 @copyprop4(i32 %a, i32 %b) { ret i32 %a }
+  define i32 @copyprop5(i32 %a, i32 %b) { ret i32 %a }
+  define i32 @copyprop6(i32 %a, i32 %b) { ret i32 %a }
   declare i32 @foo(i32)
 ...
 ---
@@ -65,3 +67,33 @@ body: |
     RET_ReallyLR implicit $w0
 ...
 
+# Don't try to erase any COPY which overlaps itself.
+# CHECK-LABEL: name: copyprop5
+# CHECK: bb.0:
+# CHECK: COPY killed $q26_q27_q28_q29
+# CHECK: COPY killed $q28_q29_q30_q31
+name: copyprop5
+body: |
+  bb.0:
+    liveins: $q26_q27_q28_q29
+    $q28_q29_q30_q31 = COPY killed $q26_q27_q28_q29
+    $q26_q27_q28_q29 = COPY killed $q28_q29_q30_q31
+    BL @foo, csr_aarch64_aapcs, implicit killed $q26_q27_q28_q29
+    RET_ReallyLR
+...
+
+# Don't try to analyze any COPY which overlaps itself.
+# CHECK-LABEL: name: copyprop6
+# CHECK: bb.0:
+# CHECK: COPY killed $q26_q27_q28_q29
+# CHECK: $q30 = COPY $q28
+name: copyprop6
+body: |
+  bb.0:
+    liveins: $q26_q27_q28_q29
+    $q28_q29_q30_q31 = COPY killed $q26_q27_q28_q29
+    $q30 = COPY $q28
+    BL @foo, csr_aarch64_aapcs, implicit killed $q28_q29_q30_q31
+    RET_ReallyLR
+...
+




More information about the llvm-commits mailing list