https://github.com/MitchBriles updated 
https://github.com/llvm/llvm-project/pull/240473

>From 7acc4d697a8d0ffa0cea2baacdcdd048fb91ddb0 Mon Sep 17 00:00:00 2001
From: Mitch <[email protected]>
Date: Fri, 23 Oct 2026 12:20:38 -0600
Subject: [PATCH 1/2] Precommit regalloc test

---
 llvm/test/CodeGen/X86/freeze-pseudo.mir | 32 +++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/llvm/test/CodeGen/X86/freeze-pseudo.mir 
b/llvm/test/CodeGen/X86/freeze-pseudo.mir
index 56f37c9d97f41..97d75e9d6b074 100644
--- a/llvm/test/CodeGen/X86/freeze-pseudo.mir
+++ b/llvm/test/CodeGen/X86/freeze-pseudo.mir
@@ -132,3 +132,35 @@ body: |
     $eax = COPY %0
     RET 0, implicit $eax
 ...
+---
+name: freeze_partially_undef
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $edi, $rsi
+
+    ; IMPDEF-LABEL: name: freeze_partially_undef
+    ; IMPDEF: liveins: $edi, $rsi
+    ; IMPDEF-NEXT: {{  $}}
+    ; IMPDEF-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
+    ; IMPDEF-NEXT: [[COPY1:%[0-9]+]]:gr64 = COPY $rsi
+    ; IMPDEF-NEXT: [[INSERT_SUBREG:%[0-9]+]]:gr64 = INSERT_SUBREG undef 
%2:gr64, [[COPY]], %subreg.sub_32bit
+    ; IMPDEF-NEXT: [[FREEZE:%[0-9]+]]:gr64 = FREEZE [[INSERT_SUBREG]]
+    ; IMPDEF-NEXT: MOV64mr [[COPY1]], 1, $noreg, 0, $noreg, [[FREEZE]]
+    ; IMPDEF-NEXT: RET 0
+    ;
+    ; RA-LABEL: name: freeze_partially_undef
+    ; RA: liveins: $edi, $rsi
+    ; RA-NEXT: {{  $}}
+    ; RA-NEXT: renamable $edi = KILL $edi, implicit-def $rdi
+    ; RA-NEXT: renamable $rax = FREEZE killed renamable $rdi
+    ; RA-NEXT: MOV64mr killed renamable $rsi, 1, $noreg, 0, $noreg, killed 
renamable $rax
+    ; RA-NEXT: RET 0
+    %0:gr32 = COPY $edi
+    %1:gr64 = COPY $rsi
+    %2:gr64 = IMPLICIT_DEF
+    %3:gr64 = INSERT_SUBREG %2, %0, %subreg.sub_32bit
+    %4:gr64 = FREEZE %3
+    MOV64mr %1, 1, $noreg, 0, $noreg, %4
+    RET 0
+...

>From 9d663d29dbefca5491f5bf50e6fbf8656f6a37da Mon Sep 17 00:00:00 2001
From: Mitch <[email protected]>
Date: Fri, 23 Oct 2026 12:21:22 -0600
Subject: [PATCH 2/2] [CodeGen] Hint to register allocator that FREEZE will
 become a copy

A FREEZE is lowered to a COPY after register allocation, so we should give
its operands the same allocation hint as a COPY. When both get the same
register, the FREEZE can be removed.
---
 llvm/lib/CodeGen/CalcSpillWeights.cpp   | 5 +++--
 llvm/test/CodeGen/X86/freeze-pseudo.mir | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp 
b/llvm/lib/CodeGen/CalcSpillWeights.cpp
index e958acdcb064a..b9e91150b3d23 100644
--- a/llvm/lib/CodeGen/CalcSpillWeights.cpp
+++ b/llvm/lib/CodeGen/CalcSpillWeights.cpp
@@ -336,8 +336,9 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI) {
       TotalWeight += Weight;
     }
 
-    // Get allocation hints from copies.
-    if (!TII.isCopyInstr(*MI))
+    // Get allocation hints from copies. A FREEZE lowers to a copy after
+    // register allocation.
+    if (!TII.isCopyInstr(*MI) && MI->getOpcode() != TargetOpcode::FREEZE)
       continue;
     Register HintReg = copyHint(MI, LI.reg(), TRI, MRI);
     if (HintReg && (HintReg.isVirtual() || MRI.isAllocatable(HintReg)))
diff --git a/llvm/test/CodeGen/X86/freeze-pseudo.mir 
b/llvm/test/CodeGen/X86/freeze-pseudo.mir
index 97d75e9d6b074..8abae6e01537f 100644
--- a/llvm/test/CodeGen/X86/freeze-pseudo.mir
+++ b/llvm/test/CodeGen/X86/freeze-pseudo.mir
@@ -153,8 +153,8 @@ body: |
     ; RA: liveins: $edi, $rsi
     ; RA-NEXT: {{  $}}
     ; RA-NEXT: renamable $edi = KILL $edi, implicit-def $rdi
-    ; RA-NEXT: renamable $rax = FREEZE killed renamable $rdi
-    ; RA-NEXT: MOV64mr killed renamable $rsi, 1, $noreg, 0, $noreg, killed 
renamable $rax
+    ; RA-NEXT: renamable $rdi = FREEZE killed renamable $rdi
+    ; RA-NEXT: MOV64mr killed renamable $rsi, 1, $noreg, 0, $noreg, killed 
renamable $rdi
     ; RA-NEXT: RET 0
     %0:gr32 = COPY $edi
     %1:gr64 = COPY $rsi

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to