Skip to content

Conversation

@petar-avramovic
Copy link
Collaborator

Used to fail EXPENSIVE_CHECKS because of type mismatch.

Copy link
Collaborator Author

petar-avramovic commented Feb 3, 2026

@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2026

@llvm/pr-subscribers-llvm-globalisel

@llvm/pr-subscribers-backend-amdgpu

Author: Petar Avramovic (petar-avramovic)

Changes

Used to fail EXPENSIVE_CHECKS because of type mismatch.


Full diff: https://github.com/llvm/llvm-project/pull/179441.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp (+5-3)
  • (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/unmerge-sgpr-s16.mir (+4-4)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp
index 445150d9dfe5e..4f4f1cbf2b0d6 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp
@@ -1044,9 +1044,11 @@ bool RegBankLegalizeHelper::lower(MachineInstr &MI,
 
     B.setInstrAndDebugLoc(MI);
     if (Ty.getSizeInBits() > 32) {
-      auto Unmerge32 = B.buildUnmerge(SgprRB_S32, Unmerge->getSourceReg());
-      for (unsigned i = 0; i < Unmerge32->getNumDefs(); ++i) {
-        auto [Dst0S32, Dst1S32] = unpackAExt(Unmerge32->getOperand(i).getReg());
+      auto UnmergeV2S16 =
+          B.buildUnmerge({SgprRB, V2S16}, Unmerge->getSourceReg());
+      for (unsigned i = 0; i < UnmergeV2S16->getNumDefs(); ++i) {
+        auto [Dst0S32, Dst1S32] =
+            unpackAExt(UnmergeV2S16->getOperand(i).getReg());
         B.buildTrunc(MI.getOperand(i * 2).getReg(), Dst0S32);
         B.buildTrunc(MI.getOperand(i * 2 + 1).getReg(), Dst1S32);
       }
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/unmerge-sgpr-s16.mir b/llvm/test/CodeGen/AMDGPU/GlobalISel/unmerge-sgpr-s16.mir
index 39eaa44bdd090..94a59eb1a92b2 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/unmerge-sgpr-s16.mir
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/unmerge-sgpr-s16.mir
@@ -1,5 +1,5 @@
 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
-# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -run-pass=amdgpu-regbanklegalize %s -o - | FileCheck %s
+# RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -run-pass=amdgpu-regbanklegalize -verify-machineinstrs %s -o - | FileCheck %s
 
 ---
 name: unmerge_sgprS16_from_V2S16
@@ -42,13 +42,13 @@ body: |
     ; CHECK-NEXT: {{  $}}
     ; CHECK-NEXT: [[COPY:%[0-9]+]]:sgpr(<4 x s16>) = COPY $sgpr0_sgpr1
     ; CHECK-NEXT: [[COPY1:%[0-9]+]]:sgpr(p1) = COPY $sgpr2_sgpr3
-    ; CHECK-NEXT: [[UV:%[0-9]+]]:sgpr(s32), [[UV1:%[0-9]+]]:sgpr(s32) = G_UNMERGE_VALUES [[COPY]](<4 x s16>)
-    ; CHECK-NEXT: [[BITCAST:%[0-9]+]]:sgpr(s32) = G_BITCAST [[UV]](s32)
+    ; CHECK-NEXT: [[UV:%[0-9]+]]:sgpr(<2 x s16>), [[UV1:%[0-9]+]]:sgpr(<2 x s16>) = G_UNMERGE_VALUES [[COPY]](<4 x s16>)
+    ; CHECK-NEXT: [[BITCAST:%[0-9]+]]:sgpr(s32) = G_BITCAST [[UV]](<2 x s16>)
     ; CHECK-NEXT: [[C:%[0-9]+]]:sgpr(s32) = G_CONSTANT i32 16
     ; CHECK-NEXT: [[LSHR:%[0-9]+]]:sgpr(s32) = G_LSHR [[BITCAST]], [[C]](s32)
     ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:sgpr(s16) = G_TRUNC [[BITCAST]](s32)
     ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:sgpr(s16) = G_TRUNC [[LSHR]](s32)
-    ; CHECK-NEXT: [[BITCAST1:%[0-9]+]]:sgpr(s32) = G_BITCAST [[UV1]](s32)
+    ; CHECK-NEXT: [[BITCAST1:%[0-9]+]]:sgpr(s32) = G_BITCAST [[UV1]](<2 x s16>)
     ; CHECK-NEXT: [[LSHR1:%[0-9]+]]:sgpr(s32) = G_LSHR [[BITCAST1]], [[C]](s32)
     ; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:sgpr(s16) = G_TRUNC [[BITCAST1]](s32)
     ; CHECK-NEXT: [[TRUNC3:%[0-9]+]]:sgpr(s16) = G_TRUNC [[LSHR1]](s32)

@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2-mir-test branch from b2fe23e to d0b552e Compare February 3, 2026 12:01
@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2 branch 2 times, most recently from 516cd21 to f0b184a Compare February 3, 2026 12:02
@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2-mir-test branch from d0b552e to aff1d33 Compare February 3, 2026 12:20
@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2 branch from f0b184a to 2ba1b05 Compare February 3, 2026 12:20
@petar-avramovic
Copy link
Collaborator Author

Copy link
Collaborator Author

petar-avramovic commented Feb 3, 2026

Merge activity

  • Feb 3, 3:26 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 3, 4:02 PM UTC: The Graphite merge of this pull request was cancelled.

@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2-mir-test branch 6 times, most recently from 10778f3 to 70eda52 Compare February 3, 2026 16:15
@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2 branch from 2ba1b05 to 8ae25a2 Compare February 3, 2026 16:15
Base automatically changed from users/petar-avramovic/fix-unmerge-s16-v2-mir-test to main February 3, 2026 16:46
Used to fail EXPENSIVE_CHECKS because of type mismatch.
@petar-avramovic petar-avramovic force-pushed the users/petar-avramovic/fix-unmerge-s16-v2 branch from 8ae25a2 to 50f8d63 Compare February 3, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants