[llvm] [MCP] Disable BackwardCopyPropagateBlock for copies with implicit registers. (PR #137687)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 28 13:20:54 PDT 2025


https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/137687

>From 22eef11ff4056f1b5234a4d2e4212e3c3dcbd960 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 28 Apr 2025 11:34:10 -0700
Subject: [PATCH 1/2] Pre-commit test

---
 llvm/test/CodeGen/SystemZ/pr137687.mir | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 llvm/test/CodeGen/SystemZ/pr137687.mir

diff --git a/llvm/test/CodeGen/SystemZ/pr137687.mir b/llvm/test/CodeGen/SystemZ/pr137687.mir
new file mode 100644
index 0000000000000..c3cf4f4eb7bf4
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/pr137687.mir
@@ -0,0 +1,20 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc %s -mtriple=s390x-unknown-linux-gnu -run-pass=machine-cp -verify-machineinstrs -o - | FileCheck %s
+
+---
+name:            t
+tracksRegLiveness: true
+noPhis:          true
+isSSA:           false
+noVRegs:         true
+hasFakeUses:     false
+tracksDebugUserValues: true
+body:             |
+  bb.0:
+    ; CHECK-LABEL: name: t
+    ; CHECK: renamable $r12d = LLILL 0
+    ; CHECK-NEXT: Return implicit $r12q
+    renamable $r14d = LLILL 0
+    renamable $r12d = COPY killed renamable $r14d, implicit-def $r12q
+    Return implicit $r12q
+...

>From e0a7a58460ef75d24193f97b581eb06922654adf Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 28 Apr 2025 11:35:20 -0700
Subject: [PATCH 2/2] [MCP] Disable BackwardCopyPropagateBlock for copies with
 implicit registers.

If there's an implicit-def of a super register, the propagation
must preserve this implicit-def. Knowing how and when to do this
may require target specific knowledge so just disable it for now.

Prior to e17f07c, we checked that the copy had explicit 2 operands
when that was removed we started allowing implicit operands through.
This patch adds a check for implicit operands, but still allows
extra explicit operands which was the goal of e17f07c.

Fixes #137667.
---
 llvm/lib/CodeGen/MachineCopyPropagation.cpp | 2 +-
 llvm/test/CodeGen/SystemZ/pr137687.mir      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index ff75b87b23128..9e82b5caed0d0 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -1200,7 +1200,7 @@ void MachineCopyPropagation::BackwardCopyPropagateBlock(
     // Ignore non-trivial COPYs.
     std::optional<DestSourcePair> CopyOperands =
         isCopyInstr(MI, *TII, UseCopyInstr);
-    if (CopyOperands) {
+    if (CopyOperands && MI.getNumImplicitOperands() == 0) {
       Register DefReg = CopyOperands->Destination->getReg();
       Register SrcReg = CopyOperands->Source->getReg();
 
diff --git a/llvm/test/CodeGen/SystemZ/pr137687.mir b/llvm/test/CodeGen/SystemZ/pr137687.mir
index c3cf4f4eb7bf4..66038f9dce22f 100644
--- a/llvm/test/CodeGen/SystemZ/pr137687.mir
+++ b/llvm/test/CodeGen/SystemZ/pr137687.mir
@@ -12,7 +12,8 @@ tracksDebugUserValues: true
 body:             |
   bb.0:
     ; CHECK-LABEL: name: t
-    ; CHECK: renamable $r12d = LLILL 0
+    ; CHECK: renamable $r14d = LLILL 0
+    ; CHECK-NEXT: renamable $r12d = COPY killed renamable $r14d, implicit-def $r12q
     ; CHECK-NEXT: Return implicit $r12q
     renamable $r14d = LLILL 0
     renamable $r12d = COPY killed renamable $r14d, implicit-def $r12q



More information about the llvm-commits mailing list