[llvm] [X86][GlobalISel] Ignore non-vregs in regbank mapping (PR #182880)
Tommy Chiang via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 19 13:48:59 PDT 2026
https://github.com/oToToT updated https://github.com/llvm/llvm-project/pull/182880
>From cd89ed95dccdb446535e40338d382e68186277b8 Mon Sep 17 00:00:00 2001
From: Tommy Chiang <ototot at google.com>
Date: Mon, 23 Feb 2026 22:04:16 +0800
Subject: [PATCH] [X86][GlobalISel] Ignore non-vregs in regbank mapping
`X86RegisterBankInfo`'s regbank-mapping helpers work under the
assumption that every register operand was a typed virtual register.
This caused `RegBankSelect` crashes when such operands reached these
helpers:
* `getInstrPartialMappingIdxs` called `MRI.getType()` on a non-vreg
operand.
* `getInstrValueMapping` then called `getValueMapping(PMI_None, ...)`
for it.
Skip non-virtual register operands in both helpers. This keeps non-vregs
out of LLT/mapping logic while still mapping real vreg operands.
Fixes https://github.com/llvm/llvm-project/issues/182735
---
.../Target/X86/GISel/X86RegisterBankInfo.cpp | 4 +--
.../regbankselect-dbg-value-physreg-crash.mir | 34 +++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir
diff --git a/llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp b/llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp
index b23d791501729..8764cfc44613f 100644
--- a/llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp
+++ b/llvm/lib/Target/X86/GISel/X86RegisterBankInfo.cpp
@@ -201,7 +201,7 @@ void X86RegisterBankInfo::getInstrPartialMappingIdxs(
unsigned NumOperands = MI.getNumOperands();
for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
auto &MO = MI.getOperand(Idx);
- if (!MO.isReg() || !MO.getReg())
+ if (!MO.isReg() || !MO.getReg().isVirtual())
OpRegBankIdx[Idx] = PMI_None;
else
OpRegBankIdx[Idx] =
@@ -218,7 +218,7 @@ bool X86RegisterBankInfo::getInstrValueMapping(
for (unsigned Idx = 0; Idx < NumOperands; ++Idx) {
if (!MI.getOperand(Idx).isReg())
continue;
- if (!MI.getOperand(Idx).getReg())
+ if (!MI.getOperand(Idx).getReg().isVirtual())
continue;
auto Mapping = getValueMapping(OpRegBankIdx[Idx], 1);
diff --git a/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir b/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir
new file mode 100644
index 0000000000000..79523b904ee9a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/GlobalISel/regbankselect-dbg-value-physreg-crash.mir
@@ -0,0 +1,34 @@
+# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=regbankselect -verify-machineinstrs %s -o - | FileCheck %s
+# RUN: llc -mtriple=x86_64-linux-gnu -regbankselect-greedy -run-pass=regbankselect -verify-machineinstrs %s -o - | FileCheck %s
+
+# This reproduces a pre-regbankselect GMIR where DBG_VALUE already carries a
+# physical register. Regressions here used to crash when X86RegisterBankInfo
+# queried LLT for non-vreg register operands.
+
+--- |
+ define void @foo() {
+ entry:
+ ret void
+ }
+
+ !0 = distinct !DISubprogram(name: "foo")
+ !1 = !DILocation(line: 1, column: 1, scope: !0)
+...
+
+---
+name: foo
+legalized: true
+regBankSelected: false
+body: |
+ bb.0:
+ liveins: $rdi
+
+ %0:_(p0) = COPY $rdi
+ DBG_VALUE $rdi, $noreg, 0, 0, debug-location !1
+ RET 0
+
+...
+
+# CHECK-LABEL: name: foo
+# CHECK: %0:gpr(p0) = COPY $rdi
+# CHECK: DBG_VALUE $rdi, $noreg, 0, 0
More information about the llvm-commits
mailing list