Skip to content

[AMDGPU][MC] Disassembler warning for v_cmpx instructions #127925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

jwanggit86
Copy link
Contributor

For GFX10+ the destnation reg of v_cmpx instructions is implicitly EXEC, which is encoded as 0x7E. However, the disassembler does not check this field, thus allowing any value. With this patch, if the field is not 0x7E a warning is issued.

For GFX10+ the destnation reg of v_cmpx instructions is
implicitly EXEC, which is encoded as 0x7E. However, the
disassembler does not check this field, thus allowing any
value. With this patch, if the field is not 0x7E a warning
is issued.
@jwanggit86 jwanggit86 added backend:AMDGPU mc Machine (object) code labels Feb 20, 2025
@jwanggit86 jwanggit86 requested review from jayfoad and arsenm February 20, 2025 00:33
@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-mc

Author: Jun Wang (jwanggit86)

Changes

For GFX10+ the destnation reg of v_cmpx instructions is implicitly EXEC, which is encoded as 0x7E. However, the disassembler does not check this field, thus allowing any value. With this patch, if the field is not 0x7E a warning is issued.


Patch is 22.34 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/127925.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp (+11-1)
  • (added) llvm/test/MC/Disassembler/AMDGPU/gfx10_vop3cx_warn.txt (+407)
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 308ab8e3b82c4..cd74ff5a34c42 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -663,6 +663,8 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
     return MCDisassembler::Fail;
   } while (false);
 
+  DecodeStatus Status = MCDisassembler::Success;
+
   if (MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::DPP) {
     if (isMacDPP(MI))
       convertMacDPPInst(MI);
@@ -801,8 +803,16 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
   if (ImmLitIdx != -1 && !IsSOPK)
     convertFMAanyK(MI, ImmLitIdx);
 
+  if (isGFX10Plus() &&
+      (MCII->get(MI.getOpcode()).TSFlags & SIInstrFlags::VOP3) &&
+      MCII->get(MI.getOpcode()).hasImplicitDefOfPhysReg(AMDGPU::EXEC)) {
+    auto ExecEncoding = MRI.getEncodingValue(AMDGPU::EXEC_LO);
+    if (Bytes_[0] != ExecEncoding)
+      Status = MCDisassembler::SoftFail;
+  }
+
   Size = MaxInstBytesNum - Bytes.size();
-  return MCDisassembler::Success;
+  return Status;
 }
 
 void AMDGPUDisassembler::convertEXPInst(MCInst &MI) const {
diff --git a/llvm/test/MC/Disassembler/AMDGPU/gfx10_vop3cx_warn.txt b/llvm/test/MC/Disassembler/AMDGPU/gfx10_vop3cx_warn.txt
new file mode 100644
index 0000000000000..b8bf696cf9fd3
--- /dev/null
+++ b/llvm/test/MC/Disassembler/AMDGPU/gfx10_vop3cx_warn.txt
@@ -0,0 +1,407 @@
+# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1010 -disassemble -show-encoding < %s 2>&1 | FileCheck -check-prefixes=GFX10 %s
+
+### class
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_class_f16_e64 v1, v2             ; encoding: [0x7e,0x00,0x9f,0xd4,0x01,0x05,0x02,0x00]
+0x00,0x00,0x9f,0xd4,0x01,0x05,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_class_f32_e64 v1, v2             ; encoding: [0x7e,0x00,0x98,0xd4,0x01,0x05,0x02,0x00]
+0x01,0x00,0x98,0xd4,0x01,0x05,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_class_f64_e64 s[4:5], v2         ; encoding: [0x7e,0x00,0xb8,0xd4,0x04,0x04,0x02,0x00]
+0x02,0x00,0xb8,0xd4,0x04,0x04,0x02,0x00
+
+### eq
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_f16_e64 0.5, v2               ; encoding: [0x7e,0x00,0xda,0xd4,0xf0,0x04,0x02,0x00]
+0x03,0x00,0xda,0xd4,0xf0,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_f32_e64 -4.0, v2              ; encoding: [0x7e,0x00,0x12,0xd4,0xf7,0x04,0x02,0x00]
+0x04,0x00,0x12,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_f64_e64 v[1:2], -4.0          ; encoding: [0x7e,0x00,0x32,0xd4,0x01,0xef,0x01,0x00]
+0x05,0x00,0x32,0xd4,0x01,0xef,0x01,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_i16_e64 -1, v2                ; encoding: [0x7e,0x00,0x9a,0xd4,0xc1,0x04,0x02,0x00]
+0x06,0x00,0x9a,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_i32_e64 -1, v2                ; encoding: [0x7e,0x00,0x92,0xd4,0xc1,0x04,0x02,0x00]
+0x07,0x00,0x92,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_i64_e64 -1, v[2:3]            ; encoding: [0x7e,0x00,0xb2,0xd4,0xc1,0x04,0x02,0x00]
+0x08,0x00,0xb2,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_u16_e64 s1, v2                ; encoding: [0x7e,0x00,0xba,0xd4,0x01,0x04,0x02,0x00]
+0x09,0x00,0xba,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_u32_e64 s1, v2                ; encoding: [0x7e,0x00,0xd2,0xd4,0x01,0x04,0x02,0x00]
+0x0a,0x00,0xd2,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_eq_u64_e64 s[2:3], v[2:3]        ; encoding: [0x7e,0x00,0xf2,0xd4,0x02,0x04,0x02,0x00]
+0x0b,0x00,0xf2,0xd4,0x02,0x04,0x02,0x00
+
+### f_f
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_f16_e64 -4.0, v2               ; encoding: [0x7e,0x00,0xd8,0xd4,0xf7,0x04,0x02,0x00]
+0x0c,0x00,0xd8,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_f32_e64 -4.0, v2               ; encoding: [0x7e,0x00,0x10,0xd4,0xf7,0x04,0x02,0x00]
+0x0d,0x00,0x10,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_f64_e64 -4.0, v[2:3]           ; encoding: [0x7e,0x00,0x30,0xd4,0xf7,0x04,0x02,0x00]
+0x0e,0x00,0x30,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_i32_e64 -1, v2                 ; encoding: [0x7e,0x00,0x90,0xd4,0xc1,0x04,0x02,0x00]
+0x0f,0x00,0x90,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_i64_e64 -1, v[2:3]             ; encoding: [0x7e,0x00,0xb0,0xd4,0xc1,0x04,0x02,0x00]
+0x10,0x00,0xb0,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_u32_e64 s1, v2                 ; encoding: [0x7e,0x00,0xd0,0xd4,0x01,0x04,0x02,0x00]
+0x11,0x00,0xd0,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_f_u64_e64 s[2:3], v[2:3]         ; encoding: [0x7e,0x00,0xf0,0xd4,0x02,0x04,0x02,0x00]
+0x12,0x00,0xf0,0xd4,0x02,0x04,0x02,0x00
+
+### ge
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_f16_e64 -4.0, v2              ; encoding: [0x7e,0x00,0xde,0xd4,0xf7,0x04,0x02,0x00]
+0x13,0x00,0xde,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_f32_e64 -4.0, v2              ; encoding: [0x7e,0x00,0x16,0xd4,0xf7,0x04,0x02,0x00]
+0x14,0x00,0x16,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_f64_e64 -4.0, v[2:3]          ; encoding: [0x7e,0x00,0x36,0xd4,0xf7,0x04,0x02,0x00]
+0x15,0x00,0x36,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_i16_e64 -1, v2                ; encoding: [0x7e,0x00,0x9e,0xd4,0xc1,0x04,0x02,0x00]
+0x16,0x00,0x9e,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_i32_e64 -1, v2                ; encoding: [0x7e,0x00,0x96,0xd4,0xc1,0x04,0x02,0x00]
+0x17,0x00,0x96,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_i64_e64 -1, v[2:3]            ; encoding: [0x7e,0x00,0xb6,0xd4,0xc1,0x04,0x02,0x00]
+0x18,0x00,0xb6,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_u16_e64 -1, v2                ; encoding: [0x7e,0x00,0xbe,0xd4,0xc1,0x04,0x02,0x00]
+0x19,0x00,0xbe,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_u16_e64 v1, m0                ; encoding: [0x7e,0x00,0xbe,0xd4,0x01,0xf9,0x00,0x00]
+0x1a,0x00,0xbe,0xd4,0x01,0xf9,0x00,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_u32_e64 v1, m0                ; encoding: [0x7e,0x00,0xd6,0xd4,0x01,0xf9,0x00,0x00]
+0x1b,0x00,0xd6,0xd4,0x01,0xf9,0x00,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ge_u64_e64 exec, v[2:3]          ; encoding: [0x7e,0x00,0xf6,0xd4,0x7e,0x04,0x02,0x00]
+0x1c,0x00,0xf6,0xd4,0x7e,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_f16_e64 -4.0, v2              ; encoding: [0x7e,0x00,0xdc,0xd4,0xf7,0x04,0x02,0x00]
+0x1d,0x00,0xdc,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_f32_e64 -4.0, v2              ; encoding: [0x7e,0x00,0x14,0xd4,0xf7,0x04,0x02,0x00]
+0x1e,0x00,0x14,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_f64_e64 -4.0, v[2:3]          ; encoding: [0x7e,0x00,0x34,0xd4,0xf7,0x04,0x02,0x00]
+0x1f,0x00,0x34,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_i16_e64 -1, v2                ; encoding: [0x7e,0x00,0x9c,0xd4,0xc1,0x04,0x02,0x00]
+0x20,0x00,0x9c,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_i32_e64 -1, v2                ; encoding: [0x7e,0x00,0x94,0xd4,0xc1,0x04,0x02,0x00]
+0x21,0x00,0x94,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_i64_e64 -1, v[2:3]            ; encoding: [0x7e,0x00,0xb4,0xd4,0xc1,0x04,0x02,0x00]
+0x22,0x00,0xb4,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_u16_e64 s1, v2                ; encoding: [0x7e,0x00,0xbc,0xd4,0x01,0x04,0x02,0x00]
+0x23,0x00,0xbc,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_u32_e64 s1, v2                ; encoding: [0x7e,0x00,0xd4,0xd4,0x01,0x04,0x02,0x00]
+0x24,0x00,0xd4,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_gt_u64_e64 s[2:3], v[2:3]        ; encoding: [0x7e,0x00,0xf4,0xd4,0x02,0x04,0x02,0x00]
+0x25,0x00,0xf4,0xd4,0x02,0x04,0x02,0x00
+
+### le
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_f16_e64 -4.0, v2              ; encoding: [0x7e,0x00,0xdb,0xd4,0xf7,0x04,0x02,0x00]
+0x26,0x00,0xdb,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_f32_e64 -4.0, v2              ; encoding: [0x7e,0x00,0x13,0xd4,0xf7,0x04,0x02,0x00]
+0x27,0x00,0x13,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_f64_e64 -4.0, v[2:3]          ; encoding: [0x7e,0x00,0x33,0xd4,0xf7,0x04,0x02,0x00]
+0x28,0x00,0x33,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_i16_e64 -1, v2                ; encoding: [0x7e,0x00,0x9b,0xd4,0xc1,0x04,0x02,0x00]
+0x29,0x00,0x9b,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_i32_e64 -1, v2                ; encoding: [0x7e,0x00,0x93,0xd4,0xc1,0x04,0x02,0x00]
+0x2a,0x00,0x93,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_i64_e64 -1, v[2:3]            ; encoding: [0x7e,0x00,0xb3,0xd4,0xc1,0x04,0x02,0x00]
+0x2b,0x00,0xb3,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_u16_e64 s1, v2                ; encoding: [0x7e,0x00,0xbb,0xd4,0x01,0x04,0x02,0x00]
+0x2e,0x00,0xbb,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_u32_e64 s1, v2                ; encoding: [0x7e,0x00,0xd3,0xd4,0x01,0x04,0x02,0x00]
+0x2f,0x00,0xd3,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_le_u64_e64 s[2:3], v[2:3]        ; encoding: [0x7e,0x00,0xf3,0xd4,0x02,0x04,0x02,0x00]
+0x30,0x00,0xf3,0xd4,0x02,0x04,0x02,0x00
+
+### lg
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lg_f16_e64 -4.0, v2              ; encoding: [0x7e,0x00,0xdd,0xd4,0xf7,0x04,0x02,0x00]
+0x31,0x00,0xdd,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lg_f32_e64 -4.0, v2              ; encoding: [0x7e,0x00,0x15,0xd4,0xf7,0x04,0x02,0x00]
+0x32,0x00,0x15,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lg_f64_e64 -4.0, v[2:3]          ; encoding: [0x7e,0x00,0x35,0xd4,0xf7,0x04,0x02,0x00]
+0x33,0x00,0x35,0xd4,0xf7,0x04,0x02,0x00
+
+### lt
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_f16_e64 -4.0, v2              ; encoding: [0x7e,0x00,0xd9,0xd4,0xf7,0x04,0x02,0x00]
+0x34,0x00,0xd9,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_f32_e64 -4.0, v2              ; encoding: [0x7e,0x00,0x11,0xd4,0xf7,0x04,0x02,0x00]
+0x35,0x00,0x11,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_f64_e64 -4.0, v[2:3]          ; encoding: [0x7e,0x00,0x31,0xd4,0xf7,0x04,0x02,0x00]
+0x36,0x00,0x31,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_i16_e64 -1, v2                ; encoding: [0x7e,0x00,0x99,0xd4,0xc1,0x04,0x02,0x00]
+0x37,0x00,0x99,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_i32_e64 -1, v2                ; encoding: [0x7e,0x00,0x91,0xd4,0xc1,0x04,0x02,0x00]
+0x38,0x00,0x91,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_i64_e64 -1, v[2:3]            ; encoding: [0x7e,0x00,0xb1,0xd4,0xc1,0x04,0x02,0x00]
+0x39,0x00,0xb1,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_u16_e64 s1, v2                ; encoding: [0x7e,0x00,0xb9,0xd4,0x01,0x04,0x02,0x00]
+0x3a,0x00,0xb9,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_u32_e64 s1, v2                ; encoding: [0x7e,0x00,0xd1,0xd4,0x01,0x04,0x02,0x00]
+0x3b,0x00,0xd1,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_lt_u64_e64 s[2:3], v[2:3]        ; encoding: [0x7e,0x00,0xf1,0xd4,0x02,0x04,0x02,0x00]
+0x3c,0x00,0xf1,0xd4,0x02,0x04,0x02,0x00
+
+### ne
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ne_i16_e64 -1, v2                ; encoding: [0x7e,0x00,0x9d,0xd4,0xc1,0x04,0x02,0x00]
+0x3d,0x00,0x9d,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ne_i32_e64 -1, v2                ; encoding: [0x7e,0x00,0x95,0xd4,0xc1,0x04,0x02,0x00]
+0x3e,0x00,0x95,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ne_i64_e64 -1, v[2:3]            ; encoding: [0x7e,0x00,0xb5,0xd4,0xc1,0x04,0x02,0x00]
+0x3f,0x00,0xb5,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ne_u16_e64 s1, v2                ; encoding: [0x7e,0x00,0xbd,0xd4,0x01,0x04,0x02,0x00]
+0x40,0x00,0xbd,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ne_u32_e64 s1, v2                ; encoding: [0x7e,0x00,0xd5,0xd4,0x01,0x04,0x02,0x00]
+0x41,0x00,0xd5,0xd4,0x01,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ne_u64_e64 s[2:3], v[2:3]        ; encoding: [0x7e,0x00,0xf5,0xd4,0x02,0x04,0x02,0x00]
+0x42,0x00,0xf5,0xd4,0x02,0x04,0x02,0x00
+
+### neq
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_neq_f16_e64 -4.0, v2             ; encoding: [0x7e,0x00,0xfd,0xd4,0xf7,0x04,0x02,0x00]
+0x43,0x00,0xfd,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_neq_f32_e64 -4.0, v2             ; encoding: [0x7e,0x00,0x1d,0xd4,0xf7,0x04,0x02,0x00]
+0x44,0x00,0x1d,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_neq_f64_e64 -4.0, v[2:3]         ; encoding: [0x7e,0x00,0x3d,0xd4,0xf7,0x04,0x02,0x00]
+0x45,0x00,0x3d,0xd4,0xf7,0x04,0x02,0x00
+
+### nge
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nge_f16_e64 -4.0, v2             ; encoding: [0x7e,0x00,0xf9,0xd4,0xf7,0x04,0x02,0x00]
+0x46,0x00,0xf9,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nge_f32_e64 -4.0, v2             ; encoding: [0x7e,0x00,0x19,0xd4,0xf7,0x04,0x02,0x00]
+0x47,0x00,0x19,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nge_f64_e64 -4.0, v[2:3]         ; encoding: [0x7e,0x00,0x39,0xd4,0xf7,0x04,0x02,0x00]
+0x48,0x00,0x39,0xd4,0xf7,0x04,0x02,0x00
+
+### ngt
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ngt_f16_e64 -4.0, v2             ; encoding: [0x7e,0x00,0xfb,0xd4,0xf7,0x04,0x02,0x00]
+0x49,0x00,0xfb,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ngt_f32_e64 -4.0, v2             ; encoding: [0x7e,0x00,0x1b,0xd4,0xf7,0x04,0x02,0x00]
+0x4a,0x00,0x1b,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_ngt_f64_e64 -4.0, v[2:3]         ; encoding: [0x7e,0x00,0x3b,0xd4,0xf7,0x04,0x02,0x00]
+0x4b,0x00,0x3b,0xd4,0xf7,0x04,0x02,0x00
+
+### nle
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nle_f16_e64 -1, v2               ; encoding: [0x7e,0x00,0xfc,0xd4,0xc1,0x04,0x02,0x00]
+0x4c,0x00,0xfc,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nle_f32_e64 -1, v2               ; encoding: [0x7e,0x00,0x1c,0xd4,0xc1,0x04,0x02,0x00]
+0x4d,0x00,0x1c,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nle_f64_e64 -1, v[2:3]           ; encoding: [0x7e,0x00,0x3c,0xd4,0xc1,0x04,0x02,0x00]
+0x4e,0x00,0x3c,0xd4,0xc1,0x04,0x02,0x00
+
+### nlg
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nlg_f16_e64 -1, v2               ; encoding: [0x7e,0x00,0xfa,0xd4,0xc1,0x04,0x02,0x00]
+0x4f,0x00,0xfa,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nlg_f32_e64 -1, v2               ; encoding: [0x7e,0x00,0x1a,0xd4,0xc1,0x04,0x02,0x00]
+0x50,0x00,0x1a,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nlg_f64_e64 -1, v[2:3]           ; encoding: [0x7e,0x00,0x3a,0xd4,0xc1,0x04,0x02,0x00]
+0x51,0x00,0x3a,0xd4,0xc1,0x04,0x02,0x00
+
+### nlt
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nlt_f16_e64 -1, v2               ; encoding: [0x7e,0x00,0xfe,0xd4,0xc1,0x04,0x02,0x00]
+0x52,0x00,0xfe,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nlt_f32_e64 -1, v2               ; encoding: [0x7e,0x00,0x1e,0xd4,0xc1,0x04,0x02,0x00]
+0x53,0x00,0x1e,0xd4,0xc1,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_nlt_f64_e64 -1, v[2:3]           ; encoding: [0x7e,0x00,0x3e,0xd4,0xc1,0x04,0x02,0x00]
+0x54,0x00,0x3e,0xd4,0xc1,0x04,0x02,0x00
+
+### o_f
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_o_f16_e64 -4.0, v2               ; encoding: [0x7e,0x00,0xdf,0xd4,0xf7,0x04,0x02,0x00]
+0x55,0x00,0xdf,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_o_f32_e64 -4.0, v2               ; encoding: [0x7e,0x00,0x17,0xd4,0xf7,0x04,0x02,0x00]
+0x56,0x00,0x17,0xd4,0xf7,0x04,0x02,0x00
+
+# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
+# v_cmpx_o_f64_e64 -4.0, v[2:3]           ; encoding: [0x7e,0x00,0x37,0xd4,0xf7,0x04,0x02,0x00]
+0x57,0x00,0x37,0xd4,0xf7,0x04,0x02,0x00
+
+### t_i
+# GFX10: [...
[truncated]

# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1010 -disassemble -show-encoding < %s 2>&1 | FileCheck -check-prefixes=GFX10 %s

### class
# GFX10: [[@LINE+2]]:1: warning: potentially undefined instruction encoding
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the instruction was more specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR 128256.

@@ -801,8 +803,16 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
if (ImmLitIdx != -1 && !IsSOPK)
convertFMAanyK(MI, ImmLitIdx);

if (isGFX10Plus() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As always, I despise generation checks. Can you comment this, or put it in some kind of named predicate function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular generation check may not be necessary. It seems that pre-gfx10 the VOPC instructions in question are not encoded as VOP3.

This check is removed in the latest commit.

Copy link
Contributor

@Sisyph Sisyph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach seems good.

@@ -0,0 +1,407 @@
# RUN: llvm-mc -triple=amdgcn -mcpu=gfx1010 -disassemble -show-encoding < %s 2>&1 | FileCheck -check-prefixes=GFX10 %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a RUN line with gfx11 and -mattr=+real-true16. You could use the script utils/update_mc_test_checks.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Only gfx10 tests have been created because I want to have the code changed approved before making more tests.

@jwanggit86 jwanggit86 merged commit bc91acc into llvm:main Feb 27, 2025
11 checks passed
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Mar 3, 2025
For GFX10+ the destination reg of v_cmpx instructions is implicitly EXEC,
which is encoded as 0x7E. However, the disassembler does not check this
field, thus allowing any value. With this patch, if the field is not
EXEC a warning is issued.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AMDGPU][MC][GFX10+] Warn when disassembling a VOP3 v_cmpx* opcode with dst!=EXEC
4 participants