[llvm-branch-commits] [llvm] [CodeGen] Hint to register allocator that FREEZE will become a copy (PR #240473)
Mitch Briles via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 10 01:54:04 PST 2026
https://github.com/MitchBriles updated https://github.com/llvm/llvm-project/pull/240473
>From ca0336d536782a984c3169eadd7c3eaa0569f258 Mon Sep 17 00:00:00 2001
From: Mitch <mitchbriles at gmail.com>
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 c247cb5ae2aae..ea88b67fe2997 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 5efda34647aa638d74826bbfdfc99fdfcd6bcc69 Mon Sep 17 00:00:00 2001
From: Mitch <mitchbriles at gmail.com>
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 ea88b67fe2997..61692c48a45a9 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
More information about the llvm-branch-commits
mailing list