From 422d379de287db614e6c12a1a09eb2d6e99020d7 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Date: Tue, 31 Jan 2023 17:43:42 +0530 Subject: [PATCH] [AMDGPU] Use tablegen to list uniform intrinsics Right now we do opcode wise matching to identify uniform/non-divergent AMDGPU intrinsics. It is duplicated at 2 places once at IR level uniformity analysis and at MIR level. Moving them to single tablegen table for consistency and adding and API rapper to access them. Reviewed By: arsenm, #amdgpu Differential Revision: https://reviews.llvm.org/D142961 --- llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td | 19 +++++++++++++++++++ llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp | 15 ++------------- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 10 ++-------- llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp | 10 ++++++++++ llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h | 3 +++ 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td b/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td index ca714ba..b11e5e4 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td +++ b/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td @@ -379,3 +379,22 @@ def : SourceOfDivergence; foreach intr = AMDGPUImageDimAtomicIntrinsics in def : SourceOfDivergence; + +class AlwaysUniform { + Intrinsic Intr = intr; +} + +def UniformIntrinsics : GenericTable { + let FilterClass = "AlwaysUniform"; + let Fields = ["Intr"]; + + let PrimaryKey = ["Intr"]; + let PrimaryKeyName = "lookupAlwaysUniform"; +} + +def : AlwaysUniform; +def : AlwaysUniform; +def : AlwaysUniform; +def : AlwaysUniform; +def : AlwaysUniform; +def : AlwaysUniform; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp index 0c3324f..87e292f 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp @@ -928,19 +928,8 @@ bool GCNTTIImpl::isSourceOfDivergence(const Value *V) const { } bool GCNTTIImpl::isAlwaysUniform(const Value *V) const { - if (const IntrinsicInst *Intrinsic = dyn_cast(V)) { - switch (Intrinsic->getIntrinsicID()) { - default: - return false; - case Intrinsic::amdgcn_readfirstlane: - case Intrinsic::amdgcn_readlane: - case Intrinsic::amdgcn_icmp: - case Intrinsic::amdgcn_fcmp: - case Intrinsic::amdgcn_ballot: - case Intrinsic::amdgcn_if_break: - return true; - } - } + if (const IntrinsicInst *Intrinsic = dyn_cast(V)) + return AMDGPU::isIntrinsicAlwaysUniform(Intrinsic->getIntrinsicID()); if (const CallInst *CI = dyn_cast(V)) { if (CI->isInlineAsm()) diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp index 9985fd4..55f0b65 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -8371,16 +8371,10 @@ SIInstrInfo::getGenericInstructionUniformity(const MachineInstr &MI) const { auto IID = static_cast(MI.getIntrinsicID()); if (AMDGPU::isIntrinsicSourceOfDivergence(IID)) return InstructionUniformity::NeverUniform; + if (AMDGPU::isIntrinsicAlwaysUniform(IID)) + return InstructionUniformity::AlwaysUniform; - // FIXME: Get a tablegen table for this. switch (IID) { - case Intrinsic::amdgcn_readfirstlane: - case Intrinsic::amdgcn_readlane: - case Intrinsic::amdgcn_icmp: - case Intrinsic::amdgcn_fcmp: - case Intrinsic::amdgcn_ballot: - case Intrinsic::amdgcn_if_break: - return InstructionUniformity::AlwaysUniform; case Intrinsic::amdgcn_if: case Intrinsic::amdgcn_else: // FIXME: Uniform if second result diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp index 4263e3e..1397729 100644 --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp @@ -2634,7 +2634,13 @@ struct SourceOfDivergence { }; const SourceOfDivergence *lookupSourceOfDivergence(unsigned Intr); +struct AlwaysUniform { + unsigned Intr; +}; +const AlwaysUniform *lookupAlwaysUniform(unsigned Intr); + #define GET_SourcesOfDivergence_IMPL +#define GET_UniformIntrinsics_IMPL #define GET_Gfx9BufferFormat_IMPL #define GET_Gfx10BufferFormat_IMPL #define GET_Gfx11PlusBufferFormat_IMPL @@ -2646,6 +2652,10 @@ bool isIntrinsicSourceOfDivergence(unsigned IntrID) { return lookupSourceOfDivergence(IntrID); } +bool isIntrinsicAlwaysUniform(unsigned IntrID) { + return lookupAlwaysUniform(IntrID); +} + const GcnBufferFormatInfo *getGcnBufferFormatInfo(uint8_t BitsPerComp, uint8_t NumComponents, uint8_t NumFormat, diff --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h index 4d34235..f202c6a 100644 --- a/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h +++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h @@ -1294,6 +1294,9 @@ inline bool isLegal64BitDPPControl(unsigned DC) { /// \returns true if the intrinsic is divergent bool isIntrinsicSourceOfDivergence(unsigned IntrID); +/// \returns true if the intrinsic is uniform +bool isIntrinsicAlwaysUniform(unsigned IntrID); + // Track defaults for fields in the MODE register. struct SIModeRegisterDefaults { /// Floating point opcodes that support exception flag gathering quiet and -- 2.7.4