summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/CodeGen/MachineCopyPropagation.cpp4
-rw-r--r--llvm/test/CodeGen/AArch64/machine-dead-copy.mir32
2 files changed, 35 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 4c1717e1ec3..8b6777f06db 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -399,7 +399,9 @@ void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
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();
diff --git a/llvm/test/CodeGen/AArch64/machine-dead-copy.mir b/llvm/test/CodeGen/AArch64/machine-dead-copy.mir
index a3d7e7cbbf7..09548f3f608 100644
--- a/llvm/test/CodeGen/AArch64/machine-dead-copy.mir
+++ b/llvm/test/CodeGen/AArch64/machine-dead-copy.mir
@@ -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
+...
+
OpenPOWER on IntegriCloud