[llvm-branch-commits] [llvm] [CodeGen] Add FREEZE target opcode (PR #240469)

Mitch Briles via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 9 13:47:01 PST 2026


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

>From cde7950690badf6c03ece4e8892a1238dcda9abf Mon Sep 17 00:00:00 2001
From: Mitch <mitchbriles at gmail.com>
Date: Fri, 23 Oct 2026 09:50:48 -0600
Subject: [PATCH] [CodeGen] Add FREEZE target opcode

Machine IR equivalent of `freeze` instruction. Unlike COPY,
ProcessImplicitDefs does not turn a `FREEZE` of an `IMPLICIT_DEF` into an
`IMPLICIT_DEF` and the register coalescer does not join it.

After register allocation, a `FREEZE` of a defined value is lowered to a
COPY. A `FREEZE` of an undefined value is kept until code emission, so
that no later pass sees the register as undefined. It emits a comment in
verbose asm (like `IMPLICIT_DEF`).

This PR doesn't select `freeze` -> `FREEZE` yet because there's some work to
do to avoid regressions.

Assisted-By: Claude Opus 5.5 <noreply at anthropic.com>
---
 llvm/docs/CodeGenerator.md                    |  11 +-
 llvm/include/llvm/Support/TargetOpcodes.def   |   4 +
 llvm/include/llvm/Target/Target.td            |   8 ++
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp    |  16 +++
 llvm/lib/CodeGen/ExpandPostRAPseudos.cpp      |   6 +
 llvm/lib/CodeGen/MachineVerifier.cpp          |   4 +
 llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp |   3 +-
 .../Target/Hexagon/HexagonVLIWPacketizer.cpp  |  10 +-
 llvm/lib/Target/SystemZ/SystemZLongBranch.cpp |   3 +-
 llvm/test/CodeGen/AMDGPU/hazard-freeze.mir    |  22 +++
 .../CodeGen/Mips/delay-slot-filler-freeze.mir |  21 +++
 llvm/test/CodeGen/X86/freeze-pseudo-asm.mir   |  20 +++
 .../test/CodeGen/X86/freeze-pseudo-expand.mir |  29 ++++
 llvm/test/CodeGen/X86/freeze-pseudo.mir       | 134 ++++++++++++++++++
 llvm/test/MachineVerifier/test_freeze.mir     |  17 +++
 .../match-table-imms.td                       |   4 +-
 llvm/test/TableGen/get-named-operand-idx.td   |  44 +++---
 17 files changed, 323 insertions(+), 33 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/hazard-freeze.mir
 create mode 100644 llvm/test/CodeGen/Mips/delay-slot-filler-freeze.mir
 create mode 100644 llvm/test/CodeGen/X86/freeze-pseudo-asm.mir
 create mode 100644 llvm/test/CodeGen/X86/freeze-pseudo-expand.mir
 create mode 100644 llvm/test/CodeGen/X86/freeze-pseudo.mir
 create mode 100644 llvm/test/MachineVerifier/test_freeze.mir

diff --git a/llvm/docs/CodeGenerator.md b/llvm/docs/CodeGenerator.md
index cd58ae7b006fd4..227b16fe9b01db 100644
--- a/llvm/docs/CodeGenerator.md
+++ b/llvm/docs/CodeGenerator.md
@@ -464,7 +464,7 @@ are no virtual registers left in the code.
 #### Undefined values, poison, and freeze
 
 After instruction selection, machine code has no exact equivalent of LLVM IR's
-`undef`, `poison`, or `freeze`.
+`undef` or `poison`.
 
 `IMPLICIT_DEF` defines a register without assigning a value. Currently, both
 `undef` and `poison` select to it in SelectionDAG and GlobalISel. Before
@@ -474,7 +474,14 @@ marks a register use as having a value that doesn't matter. Different
 instructions with `undef` uses of the same register may observe different
 values.
 
-Selectors lower `freeze` to a `COPY`. If the copied value is undefined,
+`FREEZE` gives undefined bits an arbitrary, but fixed value, so every use of its
+result observes the same value. It isn't generally treated as copy-like, so
+`ProcessImplicitDefs` and the register coalescer don't look through it. After
+register allocation, a `FREEZE` of a defined value becomes a `COPY`, and a
+`FREEZE` of an undefined value stays until code emission, where it emits no
+code.
+
+Selectors still lower `freeze` to a `COPY`. If the copied value is undefined,
 different uses can observe different values, which violates the IR semantics of
 `freeze`.
 
diff --git a/llvm/include/llvm/Support/TargetOpcodes.def b/llvm/include/llvm/Support/TargetOpcodes.def
index d9f18772e1a46c..852ab8f3c380e8 100644
--- a/llvm/include/llvm/Support/TargetOpcodes.def
+++ b/llvm/include/llvm/Support/TargetOpcodes.def
@@ -63,6 +63,10 @@ HANDLE_TARGET_OPCODE(IMPLICIT_DEF)
 /// early-clobber result operand.
 HANDLE_TARGET_OPCODE(INIT_UNDEF)
 
+/// FREEZE - Returns an arbitrary, but fixed value of the same type when the
+/// input is undefined/poison. Otherwise, copies the input.
+HANDLE_TARGET_OPCODE(FREEZE)
+
 /// SUBREG_TO_REG - Expose the value of bits in a super register.
 /// This is typically used after an instruction which writes its result to a
 /// subregister but also, as a side effect, writes some value (often zero) into
diff --git a/llvm/include/llvm/Target/Target.td b/llvm/include/llvm/Target/Target.td
index d70e8fa9918797..b201ce2a379db3 100644
--- a/llvm/include/llvm/Target/Target.td
+++ b/llvm/include/llvm/Target/Target.td
@@ -1295,6 +1295,14 @@ def INIT_UNDEF : StandardPseudoInstruction {
   let hasSideEffects = false;
   let Size = 0;
 }
+def FREEZE : StandardPseudoInstruction {
+  let OutOperandList = (outs unknown:$dst);
+  let InOperandList = (ins unknown:$src);
+  let AsmString = "";
+  let hasSideEffects = false;
+  let Size = 0;
+  let isMeta = true;
+}
 def SUBREG_TO_REG : StandardPseudoInstruction {
   let OutOperandList = (outs unknown:$dst);
   let InOperandList = (ins unknown:$subsrc, i32imm:$subidx);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 37822e36d6ed1f..b17125ef945b31 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1254,6 +1254,16 @@ void AsmPrinter::emitImplicitDef(const MachineInstr *MI) const {
   OutStreamer->addBlankLine();
 }
 
+static void emitFreeze(const MachineInstr *MI, AsmPrinter &AP) {
+  std::string Str;
+  raw_string_ostream OS(Str);
+  OS << "freeze: "
+     << printReg(MI->getOperand(0).getReg(),
+                 AP.MF->getSubtarget().getRegisterInfo());
+  AP.OutStreamer->AddComment(Str);
+  AP.OutStreamer->addBlankLine();
+}
+
 static void emitKill(const MachineInstr *MI, AsmPrinter &AP) {
   std::string Str;
   raw_string_ostream OS(Str);
@@ -2267,6 +2277,12 @@ void AsmPrinter::emitFunctionBody() {
         // This is only used to influence register allocation behavior, no
         // actual initialization is needed.
         break;
+      case TargetOpcode::FREEZE:
+        // Only a FREEZE of an undefined value is left. Whatever the register
+        // holds is a valid frozen value.
+        if (isVerbose())
+          emitFreeze(&MI, *this);
+        break;
       case TargetOpcode::RELOC_NONE: {
         // Generate a temporary label for the current PC.
         MCSymbol *Sym = OutContext.createTempSymbol("reloc_none");
diff --git a/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp b/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp
index fb65500e7dc7f8..4e7184a8f83aa1 100644
--- a/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp
+++ b/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp
@@ -145,6 +145,12 @@ bool ExpandPostRA::run(MachineFunction &MF) {
       case TargetOpcode::SUBREG_TO_REG:
         MadeChange |= LowerSubregToReg(&MI);
         break;
+      case TargetOpcode::FREEZE:
+        // A FREEZE of an undefined value stays a definition until emission.
+        if (MI.getOperand(1).isUndef())
+          continue;
+        MI.setDesc(TII->get(TargetOpcode::COPY));
+        [[fallthrough]];
       case TargetOpcode::COPY:
         TII->lowerCopy(&MI);
         MadeChange = true;
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 6e3504e2f460b7..e9dd71303f2528 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -2488,6 +2488,10 @@ void MachineVerifier::visitMachineInstrBefore(const MachineInstr *MI) {
     }
     break;
   }
+  case TargetOpcode::FREEZE:
+    if (!MI->getOperand(0).isReg() || !MI->getOperand(1).isReg())
+      report("FREEZE operands must be registers", MI);
+    break;
   case TargetOpcode::COPY_LANEMASK: {
     const MachineOperand &DstOp = MI->getOperand(0);
     const MachineOperand &SrcOp = MI->getOperand(1);
diff --git a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
index 143cee16477220..8ef0ae51e9ade5 100644
--- a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
@@ -765,7 +765,8 @@ void HexagonAsmPrinter::emitInstruction(const MachineInstr *MI) {
     MachineBasicBlock::const_instr_iterator MII = MI->getIterator();
 
     for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
-      if (!MII->isDebugInstr() && !MII->isImplicitDef())
+      if (!MII->isDebugInstr() && !MII->isImplicitDef() &&
+          MII->getOpcode() != TargetOpcode::FREEZE)
         HexagonLowerToMC(MCII, &*MII, MCB, *this);
   } else {
     HexagonLowerToMC(MCII, MI, MCB, *this);
diff --git a/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp b/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
index ae50cd17ccb7af..3c4b320828f6cc 100644
--- a/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp
@@ -850,9 +850,9 @@ bool HexagonPacketizerList::canPromoteToDotNew(const MachineInstr &MI,
   if (PI.isInlineAsm())
     return false;
 
-  // IMPLICIT_DEFs won't materialize as real instructions, so .new makes no
-  // sense.
-  if (PI.isImplicitDef())
+  // IMPLICIT_DEFs and FREEZEs won't materialize as real instructions, so .new
+  // makes no sense.
+  if (PI.isImplicitDef() || PI.getOpcode() == TargetOpcode::FREEZE)
     return false;
 
   // If dependency is through an implicitly defined register, we should not
@@ -1040,7 +1040,7 @@ bool HexagonPacketizerList::ignorePseudoInstruction(const MachineInstr &MI,
   if (MI.isInlineAsm())
     return false;
 
-  if (MI.isImplicitDef())
+  if (MI.isImplicitDef() || MI.getOpcode() == TargetOpcode::FREEZE)
     return false;
 
   // We check if MI has any functional units mapped to it. If it doesn't,
@@ -1707,7 +1707,7 @@ HexagonPacketizerList::addToPacket(MachineInstr &MI) {
   PacketStalls |= producesStall(MI);
   PacketStallCycles = std::max(PacketStallCycles, calcStall(MI));
 
-  if (MI.isImplicitDef()) {
+  if (MI.isImplicitDef() || MI.getOpcode() == TargetOpcode::FREEZE) {
     // Add to the packet to allow subsequent instructions to be checked
     // properly.
     CurrentPacketMIs.push_back(&MI);
diff --git a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
index ce05d7962b4929..7152df66c0ba46 100644
--- a/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZLongBranch.cpp
@@ -215,7 +215,8 @@ static unsigned getInstSizeInBytes(const MachineInstr &MI,
           // These do not have a size:
           MI.isDebugOrPseudoInstr() || MI.isPosition() || MI.isKill() ||
           MI.isImplicitDef() || MI.getOpcode() == TargetOpcode::MEMBARRIER ||
-          MI.getOpcode() == TargetOpcode::INIT_UNDEF || MI.isFakeUse() ||
+          MI.getOpcode() == TargetOpcode::INIT_UNDEF ||
+          MI.getOpcode() == TargetOpcode::FREEZE || MI.isFakeUse() ||
           MI.getOpcode() == TargetOpcode::RELOC_NONE ||
           MI.getOpcode() == SystemZ::FENCE ||
           // These have a size that may be zero:
diff --git a/llvm/test/CodeGen/AMDGPU/hazard-freeze.mir b/llvm/test/CodeGen/AMDGPU/hazard-freeze.mir
new file mode 100644
index 00000000000000..c174d2c77c8efb
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/hazard-freeze.mir
@@ -0,0 +1,22 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=amdgcn -mcpu=gfx906 -run-pass=post-RA-hazard-rec %s -o - | FileCheck %s
+
+---
+name: store_data_hazard_freeze
+body: |
+  bb.0:
+    liveins: $vgpr0_vgpr1, $vgpr2_vgpr3_vgpr4_vgpr5
+
+    ; CHECK-LABEL: name: store_data_hazard_freeze
+    ; CHECK: liveins: $vgpr0_vgpr1, $vgpr2_vgpr3_vgpr4_vgpr5
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: GLOBAL_STORE_DWORDX4 $vgpr0_vgpr1, $vgpr2_vgpr3_vgpr4_vgpr5, 0, 0, implicit $exec
+    ; CHECK-NEXT: $vgpr6 = FREEZE undef $vgpr6
+    ; CHECK-NEXT: S_NOP 0
+    ; CHECK-NEXT: $vgpr2 = V_MOV_B32_e32 0, implicit $exec
+    ; CHECK-NEXT: S_ENDPGM 0, implicit $vgpr6
+    GLOBAL_STORE_DWORDX4 $vgpr0_vgpr1, $vgpr2_vgpr3_vgpr4_vgpr5, 0, 0, implicit $exec
+    $vgpr6 = FREEZE undef $vgpr6
+    $vgpr2 = V_MOV_B32_e32 0, implicit $exec
+    S_ENDPGM 0, implicit $vgpr6
+...
diff --git a/llvm/test/CodeGen/Mips/delay-slot-filler-freeze.mir b/llvm/test/CodeGen/Mips/delay-slot-filler-freeze.mir
new file mode 100644
index 00000000000000..ce5cdbb43bedbd
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/delay-slot-filler-freeze.mir
@@ -0,0 +1,21 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=mipsel -run-pass=mips-delay-slot-filler %s -o - | FileCheck %s
+
+---
+name: freeze_not_in_delay_slot
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $r4, $r31
+
+    ; CHECK-LABEL: name: freeze_not_in_delay_slot
+    ; CHECK: liveins: $r4, $r31
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: $r2 = FREEZE undef $r2
+    ; CHECK-NEXT: PseudoReturn undef $r31, implicit $r2, implicit $r3 {
+    ; CHECK-NEXT:   $r3 = ADDiu $r4, 1
+    ; CHECK-NEXT: }
+    $r3 = ADDiu $r4, 1
+    $r2 = FREEZE undef $r2
+    PseudoReturn undef $r31, implicit $r2, implicit $r3
+...
diff --git a/llvm/test/CodeGen/X86/freeze-pseudo-asm.mir b/llvm/test/CodeGen/X86/freeze-pseudo-asm.mir
new file mode 100644
index 00000000000000..7d168a05a556cb
--- /dev/null
+++ b/llvm/test/CodeGen/X86/freeze-pseudo-asm.mir
@@ -0,0 +1,20 @@
+# NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=x86_64-- -start-before=post-ra-pseudos -o - %s | FileCheck %s
+
+--- |
+  define i32 @freeze_undef_reg() {
+  ; CHECK-LABEL: freeze_undef_reg:
+  ; CHECK:       # %bb.0:
+  ; CHECK-NEXT:    # freeze: $eax
+  ; CHECK-NEXT:    retq
+    ret i32 0
+  }
+...
+---
+name: freeze_undef_reg
+tracksRegLiveness: true
+body: |
+  bb.0:
+    $eax = FREEZE undef $ecx
+    RET 0, implicit $eax
+...
diff --git a/llvm/test/CodeGen/X86/freeze-pseudo-expand.mir b/llvm/test/CodeGen/X86/freeze-pseudo-expand.mir
new file mode 100644
index 00000000000000..cb7d415823baa9
--- /dev/null
+++ b/llvm/test/CodeGen/X86/freeze-pseudo-expand.mir
@@ -0,0 +1,29 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=x86_64-- -run-pass=post-ra-pseudos -o - %s | FileCheck %s
+
+---
+name: freeze_reg
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $edi
+
+    ; CHECK-LABEL: name: freeze_reg
+    ; CHECK: liveins: $edi
+    ; CHECK-NEXT: {{  $}}
+    ; CHECK-NEXT: $eax = MOV32rr $edi
+    ; CHECK-NEXT: RET 0, implicit $eax
+    $eax = FREEZE $edi
+    RET 0, implicit $eax
+...
+---
+name: freeze_undef_reg
+tracksRegLiveness: true
+body: |
+  bb.0:
+    ; CHECK-LABEL: name: freeze_undef_reg
+    ; CHECK: $eax = FREEZE undef $ecx
+    ; CHECK-NEXT: RET 0, implicit $eax
+    $eax = FREEZE undef $ecx
+    RET 0, implicit $eax
+...
diff --git a/llvm/test/CodeGen/X86/freeze-pseudo.mir b/llvm/test/CodeGen/X86/freeze-pseudo.mir
new file mode 100644
index 00000000000000..56f37c9d97f413
--- /dev/null
+++ b/llvm/test/CodeGen/X86/freeze-pseudo.mir
@@ -0,0 +1,134 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=x86_64-- -run-pass=process-implicit-defs -o - %s | FileCheck %s --check-prefix=IMPDEF
+# RUN: llc -mtriple=x86_64-- -run-pass=process-implicit-defs,two-address-instruction,register-coalescer,greedy,virt-reg-rewriter -o - %s | FileCheck %s --check-prefix=RA
+
+# A COPY of an IMPLICIT_DEF is undefined, so each use may read a different
+# register. Every use of a FREEZE of an IMPLICIT_DEF reads the same register.
+
+---
+name: copy_undef
+tracksRegLiveness: true
+body: |
+  bb.0:
+    ; IMPDEF-LABEL: name: copy_undef
+    ; IMPDEF: RET 0, implicit undef $eax, implicit undef $ecx
+    ;
+    ; RA-LABEL: name: copy_undef
+    ; RA: RET 0, implicit undef $eax, implicit undef $ecx
+    %0:gr32 = IMPLICIT_DEF
+    %1:gr32 = COPY %0
+    $eax = COPY %1
+    $ecx = COPY %1
+    RET 0, implicit $eax, implicit $ecx
+...
+---
+name: freeze_undef
+tracksRegLiveness: true
+body: |
+  bb.0:
+    ; IMPDEF-LABEL: name: freeze_undef
+    ; IMPDEF: [[FREEZE:%[0-9]+]]:gr32 = FREEZE undef %0:gr32
+    ; IMPDEF-NEXT: $eax = COPY [[FREEZE]]
+    ; IMPDEF-NEXT: $ecx = COPY [[FREEZE]]
+    ; IMPDEF-NEXT: RET 0, implicit $eax, implicit $ecx
+    ;
+    ; RA-LABEL: name: freeze_undef
+    ; RA: renamable $eax = FREEZE undef renamable $eax
+    ; RA-NEXT: $ecx = COPY renamable $eax
+    ; RA-NEXT: RET 0, implicit $eax, implicit $ecx
+    %0:gr32 = IMPLICIT_DEF
+    %1:gr32 = FREEZE %0
+    $eax = COPY %1
+    $ecx = COPY %1
+    RET 0, implicit $eax, implicit $ecx
+...
+---
+name: freeze_defined
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $edi
+
+    ; IMPDEF-LABEL: name: freeze_defined
+    ; IMPDEF: liveins: $edi
+    ; IMPDEF-NEXT: {{  $}}
+    ; IMPDEF-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
+    ; IMPDEF-NEXT: [[FREEZE:%[0-9]+]]:gr32 = FREEZE [[COPY]]
+    ; IMPDEF-NEXT: $eax = COPY [[FREEZE]]
+    ; IMPDEF-NEXT: $ecx = COPY [[FREEZE]]
+    ; IMPDEF-NEXT: RET 0, implicit $eax, implicit $ecx
+    ;
+    ; RA-LABEL: name: freeze_defined
+    ; RA: liveins: $edi
+    ; RA-NEXT: {{  $}}
+    ; RA-NEXT: renamable $eax = FREEZE killed renamable $edi
+    ; RA-NEXT: $ecx = COPY renamable $eax
+    ; RA-NEXT: RET 0, implicit $eax, implicit $ecx
+    %0:gr32 = COPY $edi
+    %1:gr32 = FREEZE %0
+    $eax = COPY %1
+    $ecx = COPY %1
+    RET 0, implicit $eax, implicit $ecx
+...
+---
+name: freeze_undef_cross_block
+tracksRegLiveness: true
+body: |
+  ; IMPDEF-LABEL: name: freeze_undef_cross_block
+  ; IMPDEF: bb.0:
+  ; IMPDEF-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
+  ; IMPDEF-NEXT:   liveins: $edi
+  ; IMPDEF-NEXT: {{  $}}
+  ; IMPDEF-NEXT:   [[COPY:%[0-9]+]]:gr32 = COPY $edi
+  ; IMPDEF-NEXT:   [[FREEZE:%[0-9]+]]:gr32 = FREEZE undef %1:gr32
+  ; IMPDEF-NEXT:   CMP32rr [[FREEZE]], [[COPY]], implicit-def $eflags
+  ; IMPDEF-NEXT:   JCC_1 %bb.2, 4, implicit $eflags
+  ; IMPDEF-NEXT:   JMP_1 %bb.1
+  ; IMPDEF-NEXT: {{  $}}
+  ; IMPDEF-NEXT: bb.1:
+  ; IMPDEF-NEXT:   $eax = COPY [[FREEZE]]
+  ; IMPDEF-NEXT:   RET 0, implicit $eax
+  ; IMPDEF-NEXT: {{  $}}
+  ; IMPDEF-NEXT: bb.2:
+  ; IMPDEF-NEXT:   $eax = COPY [[COPY]]
+  ; IMPDEF-NEXT:   RET 0, implicit $eax
+  ;
+  ; RA-LABEL: name: freeze_undef_cross_block
+  ; RA: bb.0:
+  ; RA-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
+  ; RA-NEXT:   liveins: $edi
+  ; RA-NEXT: {{  $}}
+  ; RA-NEXT:   renamable $eax = FREEZE undef renamable $eax
+  ; RA-NEXT:   CMP32rr renamable $eax, renamable $edi, implicit-def $eflags
+  ; RA-NEXT:   JCC_1 %bb.2, 4, implicit $eflags
+  ; RA-NEXT:   JMP_1 %bb.1
+  ; RA-NEXT: {{  $}}
+  ; RA-NEXT: bb.1:
+  ; RA-NEXT:   liveins: $eax
+  ; RA-NEXT: {{  $}}
+  ; RA-NEXT:   RET 0, implicit $eax
+  ; RA-NEXT: {{  $}}
+  ; RA-NEXT: bb.2:
+  ; RA-NEXT:   liveins: $edi
+  ; RA-NEXT: {{  $}}
+  ; RA-NEXT:   $eax = COPY killed renamable $edi
+  ; RA-NEXT:   RET 0, implicit $eax
+  bb.0:
+    successors: %bb.1, %bb.2
+    liveins: $edi
+
+    %0:gr32 = COPY $edi
+    %1:gr32 = IMPLICIT_DEF
+    %2:gr32 = FREEZE %1
+    CMP32rr %2, %0, implicit-def $eflags
+    JCC_1 %bb.2, 4, implicit $eflags
+    JMP_1 %bb.1
+
+  bb.1:
+    $eax = COPY %2
+    RET 0, implicit $eax
+
+  bb.2:
+    $eax = COPY %0
+    RET 0, implicit $eax
+...
diff --git a/llvm/test/MachineVerifier/test_freeze.mir b/llvm/test/MachineVerifier/test_freeze.mir
new file mode 100644
index 00000000000000..aa736438b4e288
--- /dev/null
+++ b/llvm/test/MachineVerifier/test_freeze.mir
@@ -0,0 +1,17 @@
+# RUN: not --crash llc -mtriple=x86_64 -run-pass=none -filetype=null %s 2>&1 | FileCheck %s -implicit-check-not="Bad machine code"
+# REQUIRES: x86-registered-target
+
+---
+name: test_freeze
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $edi
+
+    %0:gr32 = COPY $edi
+    %1:gr32 = FREEZE %0
+
+    ; CHECK: Bad machine code: FREEZE operands must be registers
+    ; CHECK: - instruction: %2:gr32 = FREEZE 0
+    %2:gr32 = FREEZE 0
+...
diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
index e20c0440726dd0..c4e3fffc3b96cf 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
@@ -87,7 +87,7 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
 // tell them apart and assumes IEEEhalf.
 //      DEFAULT: const uint8_t *GenMyCombiner::getMatchTable() const {
 // DEFAULT-NEXT:   constexpr static uint8_t MatchTable0[] = {
-// DEFAULT-NEXT:      GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(20), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 6*/ GIMT_Encode4([[LBL6:[0-9]+]]),
+// DEFAULT-NEXT:      GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(21), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 6*/ GIMT_Encode4([[LBL6:[0-9]+]]),
 // DEFAULT-NEXT:      /*TargetOpcode::COPY*//*Label 0*/ GIMT_Encode4([[LBL0:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
 // DEFAULT-NEXT:      /*TargetOpcode::G_CONSTANT*//*Label 1*/ GIMT_Encode4([[LBL1:[0-9]+]]),
 // DEFAULT-NEXT:      /*TargetOpcode::G_FCONSTANT*//*Label 2*/ GIMT_Encode4([[LBL2:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
@@ -247,7 +247,7 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
 // EXTLLT-NEXT: };
 //      EXTLLT: const uint8_t *GenMyCombiner::getMatchTable() const {
 // EXTLLT-NEXT:   constexpr static uint8_t MatchTable0[] = {
-// EXTLLT-NEXT:      GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(20), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 6*/ GIMT_Encode4([[LBL6:[0-9]+]]),
+// EXTLLT-NEXT:      GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(21), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 6*/ GIMT_Encode4([[LBL6:[0-9]+]]),
 // EXTLLT-NEXT:      /*TargetOpcode::COPY*//*Label 0*/ GIMT_Encode4([[LBL0:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
 // EXTLLT-NEXT:      /*TargetOpcode::G_CONSTANT*//*Label 1*/ GIMT_Encode4([[LBL1:[0-9]+]]),
 // EXTLLT-NEXT:      /*TargetOpcode::G_FCONSTANT*//*Label 2*/ GIMT_Encode4([[LBL2:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
diff --git a/llvm/test/TableGen/get-named-operand-idx.td b/llvm/test/TableGen/get-named-operand-idx.td
index 165d3f705c04c0..80f0f8b66b8ab0 100644
--- a/llvm/test/TableGen/get-named-operand-idx.td
+++ b/llvm/test/TableGen/get-named-operand-idx.td
@@ -78,28 +78,28 @@ defm : RemapAllTargetPseudoPointerOperands<RegClass>;
 // CHECK-EMPTY:
 // CHECK-NEXT:  LLVM_READONLY static uint8_t getInstructionIndexForOpLookup(uint32_t Opcode) {
 // CHECK-NEXT:    static constexpr uint8_t InstructionIndex[] = {
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-// CHECK-NEXT:      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
-// CHECK-NEXT:      2, 2, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// CHECK-NEXT:    1, 2, 2, 0,
 // CHECK-NEXT:    };
 // CHECK-NEXT:    return InstructionIndex[Opcode];
 // CHECK-NEXT:  }



More information about the llvm-branch-commits mailing list