[llvm] [AMDGPU] Truncate BF16 literals to 16 bits when printing (PR #225117)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 04:08:01 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
The printer emitted the full 32-bit value, so a literal with high bits set printed as text the assembler rejects
Match printImmediateF16/Int16 functions
---
Full diff: https://github.com/llvm/llvm-project/pull/225117.diff
4 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp (+1-1)
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s (+3)
- (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s (+3)
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt (+4)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
index 0aece53db1eb0..ae992d1c31fbf 100644
--- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
@@ -598,7 +598,7 @@ void AMDGPUInstPrinter::printImmediateBF16(uint32_t Imm,
if (printImmediateBFloat16(static_cast<uint16_t>(Imm), STI, O))
return;
- O << formatHex(static_cast<uint64_t>(Imm));
+ O << formatHex(static_cast<uint64_t>(Imm & 0xffff));
}
void AMDGPUInstPrinter::printImmediateF16(uint32_t Imm,
diff --git a/llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s b/llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s
index d0476d439ba4e..5b29fe895d115 100644
--- a/llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s
+++ b/llvm/test/MC/AMDGPU/gfx1250_asm_vop1-fake16.s
@@ -241,6 +241,9 @@ v_rcp_bf16 v5, src_scc
v_rcp_bf16 v127, 0x8000
// GFX1250: v_rcp_bf16_e32 v127, 0x8000 ; encoding: [0xff,0xf2,0xfe,0x7e,0x00,0x80,0x00,0x00]
+v_rcp_bf16 v5, -17
+// GFX1250: v_rcp_bf16_e32 v5, 0xffef ; encoding: [0xff,0xf2,0x0a,0x7e,0xef,0xff,0x00,0x00]
+
v_sqrt_bf16 v5, v1
// GFX1250: v_sqrt_bf16_e32 v5, v1 ; encoding: [0x01,0xf5,0x0a,0x7e]
diff --git a/llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s b/llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s
index 131432652055b..cf08791380d8b 100644
--- a/llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s
+++ b/llvm/test/MC/AMDGPU/gfx1250_asm_vop1.s
@@ -250,6 +250,9 @@ v_rcp_bf16 v5.l, src_scc
v_rcp_bf16 v127.l, 0x8000
// GFX1250: v_rcp_bf16_e32 v127.l, 0x8000 ; encoding: [0xff,0xf2,0xfe,0x7e,0x00,0x80,0x00,0x00]
+v_rcp_bf16 v5.l, -17
+// GFX1250: v_rcp_bf16_e32 v5.l, 0xffef ; encoding: [0xff,0xf2,0x0a,0x7e,0xef,0xff,0x00,0x00]
+
v_rcp_bf16 v5.h, v1.h
// GFX1250: v_rcp_bf16_e32 v5.h, v1.h ; encoding: [0x81,0xf3,0x0a,0x7f]
diff --git a/llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt b/llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt
index 92cd2f5bb2b4b..bd6bc866e8fa6 100644
--- a/llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt
+++ b/llvm/test/MC/Disassembler/AMDGPU/gfx1250_dasm_vop1.txt
@@ -249,6 +249,10 @@
# GFX1250-FAKE16: v_rcp_bf16_e32 v127, 0x8000 ; encoding: [0xff,0xf2,0xfe,0x7e,0x00,0x80,0x00,0x00]
# GFX1250-REAL16: v_rcp_bf16_e32 v127.l, 0x8000 ; encoding: [0xff,0xf2,0xfe,0x7e,0x00,0x80,0x00,0x00]
+0xff,0xf2,0x02,0x7e,0x34,0x12,0xcd,0xab
+# GFX1250-FAKE16: v_rcp_bf16_e32 v1, 0x1234 ; encoding: [0xff,0xf2,0x02,0x7e,0x34,0x12,0x00,0x00]
+# GFX1250-REAL16: v_rcp_bf16_e32 v1.l, 0x1234 ; encoding: [0xff,0xf2,0x02,0x7e,0x34,0x12,0x00,0x00]
+
0xc1,0xf2,0x0a,0x7e
# GFX1250-FAKE16: v_rcp_bf16_e32 v5, -1 ; encoding: [0xc1,0xf2,0x0a,0x7e]
# GFX1250-REAL16: v_rcp_bf16_e32 v5.l, -1 ; encoding: [0xc1,0xf2,0x0a,0x7e]
``````````
</details>
https://github.com/llvm/llvm-project/pull/225117
More information about the llvm-commits
mailing list