[llvm] [AMDGPU] Handle high element extraction with G_UNMERGE_VALUES (PR #188287)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue May 12 04:32:41 PDT 2026


================
@@ -2837,6 +2837,26 @@ static Register stripBitCast(Register Reg, MachineRegisterInfo &MRI) {
 
 static bool isExtractHiElt(MachineRegisterInfo &MRI, Register In,
                            Register &Out) {
+  // When unmerging an sgpr that is composed of 2 x s16 we need to use
+  // an extract hi instruction for the upper 16 bits.
+  //
+  // ```
+  // %0:sgpr(s16), %1:sgpr(s16) = G_UNMERGE_VALUES %2:sgpr(<2 x s16>)
+  // ```
+  //
+  // First we check that the G_UNMERGE_VALUES is in the form specified above
+  // and then return true if the requested operand is the one mapped to higher
+  // 16 bits. Also set the Out to be the source of G_UNMERGE_VALUES directly.
+  MachineInstr *Unmerge = MRI.getVRegDef(In);
+  if (Unmerge->getOpcode() == AMDGPU::G_UNMERGE_VALUES &&
----------------
arsenm wrote:

Use `dyn_cast<GUnmerge>` and the helpers on it?

https://github.com/llvm/llvm-project/pull/188287


More information about the llvm-commits mailing list