From 6f437117af2fa9f380b0d866cd203aad6c30c9b1 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 22 Jul 2020 12:27:50 -0400 Subject: [PATCH] AMDGPU: Don't assert on f16 inv2pi immediates pre-gfx8 v_cvt_f32_f16 can still accept this value as a literal constant. This showed up in GlobalISel since it doesn't have constant folding for G_FPEXT. --- llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp | 4 ++-- llvm/test/MC/AMDGPU/inline-imm-inv2pi.s | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 llvm/test/MC/AMDGPU/inline-imm-inv2pi.s diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp index 257638b..e44c019 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp @@ -424,8 +424,8 @@ void AMDGPUInstPrinter::printImmediate16(uint32_t Imm, O<< "4.0"; else if (Imm == 0xC400) O<< "-4.0"; - else if (Imm == 0x3118) { - assert(STI.getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm]); + else if (Imm == 0x3118 && + STI.getFeatureBits()[AMDGPU::FeatureInv2PiInlineImm]) { O << "0.15915494"; } else { uint64_t Imm16 = static_cast(Imm); diff --git a/llvm/test/MC/AMDGPU/inline-imm-inv2pi.s b/llvm/test/MC/AMDGPU/inline-imm-inv2pi.s new file mode 100644 index 0000000..e5ecfa2 --- /dev/null +++ b/llvm/test/MC/AMDGPU/inline-imm-inv2pi.s @@ -0,0 +1,10 @@ +// RUN: llvm-mc -arch=amdgcn -mcpu=tahiti -show-encoding %s | FileCheck -check-prefix=SI %s +// RUN: llvm-mc -arch=amdgcn -mcpu=tonga -show-encoding %s | FileCheck -check-prefix=VI %s + +// The value inv2pi should not assert on any targets, but is +// printed differently depending on whether it's a legal inline +// immediate or not. + +// SI: v_cvt_f32_f16_e32 v0, 0x3118 ; encoding: [0xff,0x16,0x00,0x7e,0x18,0x31,0x00,0x00] +// VI: v_cvt_f32_f16_e32 v0, 0.15915494 ; encoding: [0xf8,0x16,0x00,0x7e] +v_cvt_f32_f16_e32 v0, 0x3118 -- 2.7.4