[llvm] [AMDGPU] Fix disasm roundtrip for forced fp64 literal (PR #197583)
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Thu May 14 01:03:52 PDT 2026
https://github.com/rampitec updated https://github.com/llvm/llvm-project/pull/197583
>From 6990b146fd9ec5be360450320527d130cc36a8fe Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin <Stanislav.Mekhanoshin at amd.com>
Date: Wed, 13 May 2026 15:49:49 -0700
Subject: [PATCH] [AMDGPU] Fix disasm roundtrip for forced fp64 literal
---
.../lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp | 8 +++++++-
llvm/test/MC/AMDGPU/literals.s | 7 ++-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index ea928386b80c6..ea7f40ae047d8 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -1681,7 +1681,9 @@ AMDGPUDisassembler::decodeLiteralConstant(const MCInstrDesc &Desc,
case AMDGPU::OPERAND_REG_IMM_FP64:
case AMDGPU::OPERAND_REG_INLINE_C_FP64:
case AMDGPU::OPERAND_REG_INLINE_AC_FP64:
- Val <<= 32;
+ UseLit = AMDGPU::isInlinableLiteral64(Val << 32, HasInv2Pi);
+ if (!UseLit)
+ Val <<= 32;
break;
case AMDGPU::OPERAND_REG_IMM_INT64:
case AMDGPU::OPERAND_REG_INLINE_C_INT64:
@@ -1713,6 +1715,10 @@ MCOperand AMDGPUDisassembler::decodeLiteral64Constant() const {
}
bool UseLit64 = Hi_32(Literal) == 0;
+
+ // For disassembling always assume all inline constants are available.
+ UseLit64 |= AMDGPU::isInlinableLiteral64(Literal, true /* HasInv2Pi */);
+
return UseLit64 ? MCOperand::createExpr(AMDGPUMCExpr::createLit(
LitModifier::Lit64, Literal, getContext()))
: MCOperand::createImm(Literal);
diff --git a/llvm/test/MC/AMDGPU/literals.s b/llvm/test/MC/AMDGPU/literals.s
index e14d55ff62757..7dc10dced9d9a 100644
--- a/llvm/test/MC/AMDGPU/literals.s
+++ b/llvm/test/MC/AMDGPU/literals.s
@@ -194,13 +194,11 @@ v_fract_f64_e32 v[0:1], 1.0
// GFX89: v_fract_f64_e32 v[0:1], 1.0 ; encoding: [0xf2,0x64,0x00,0x7e]
// SICI: v_fract_f64_e32 v[0:1], 1.0 ; encoding: [0xf2,0x7c,0x00,0x7e]
-
-// FIXME: Forced lit() encoding is not preserved after disasm
v_fract_f64_e32 v[0:1], lit(1.0)
// GFX11: v_fract_f64_e32 v[0:1], lit(0x3ff00000) ; encoding: [0xff,0x7c,0x00,0x7e,0x00,0x00,0xf0,0x3f]
// GFX12: v_fract_f64_e32 v[0:1], lit(0x3ff00000) ; encoding: [0xff,0x7c,0x00,0x7e,0x00,0x00,0xf0,0x3f]
// GFX1250-ASM: v_fract_f64_e32 v[0:1], lit(0x3ff00000) ; encoding: [0xff,0x7c,0x00,0x7e,0x00,0x00,0xf0,0x3f]
-// GFX1250-DIS: v_fract_f64_e32 v[0:1], 1.0 ; encoding: [0xf2,0x7c,0x00,0x7e]
+// GFX1250-DIS: v_fract_f64_e32 v[0:1], lit(0x3ff00000) ; encoding: [0xff,0x7c,0x00,0x7e,0x00,0x00,0xf0,0x3f]
// GFX89: v_fract_f64_e32 v[0:1], lit(0x3ff00000) ; encoding: [0xff,0x64,0x00,0x7e,0x00,0x00,0xf0,0x3f]
// SICI: v_fract_f64_e32 v[0:1], lit(0x3ff00000) ; encoding: [0xff,0x7c,0x00,0x7e,0x00,0x00,0xf0,0x3f]
@@ -1938,12 +1936,11 @@ v_madak_f32 v4, lit(lit(0x7e8)), v8, lit(0x7e8)
// NOGFX89: :[[@LINE-4]]:24: error: not a valid operand.
// NOSICI: :[[@LINE-5]]:24: error: not a valid operand.
-// FIXME: Forced lit() encoding is not preserved after disasm
v_fract_f64_e32 v[0:1], lit64(1.0)
// NOGFX11: :[[@LINE-1]]:25: error: lit64 is not supported on this GPU
// NOGFX12: :[[@LINE-2]]:25: error: lit64 is not supported on this GPU
// GFX1250-ASM: v_fract_f64_e32 v[0:1], lit64(0x3ff0000000000000) ; encoding: [0xfe,0x7c,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f]
-// GFX1250-DIS: v_fract_f64_e32 v[0:1], 1.0 ; encoding: [0xf2,0x7c,0x00,0x7e]
+// GFX1250-DIS: v_fract_f64_e32 v[0:1], lit64(0x3ff0000000000000) ; encoding: [0xfe,0x7c,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f]
// NOGFX89: :[[@LINE-5]]:25: error: lit64 is not supported on this GPU
// NOSICI: :[[@LINE-6]]:25: error: lit64 is not supported on this GPU
More information about the llvm-commits
mailing list