diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -1930,9 +1930,20 @@ /// and point them to \p Reg instead. void changeDebugValuesDefReg(Register Reg); - /// Returns the Intrinsic::ID for this instruction. - /// \pre Must have an intrinsic ID operand. + bool isIntrinsic() const { + switch (getOpcode()) { + case TargetOpcode::G_INTRINSIC: + case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS: + return true; + default: + return false; + } + } + + /// Returns Intrinsic::ID if this is an intrinsic, else returns not_intrinsic. unsigned getIntrinsicID() const { + if (!isIntrinsic()) + return Intrinsic::not_intrinsic; return getOperand(getNumExplicitDefs()).getIntrinsicID(); } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.h b/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.h --- a/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.h @@ -21,6 +21,7 @@ class GCNSubtarget; class MachineMemOperand; +class MachineInstr; class AMDGPUInstrInfo { public: @@ -31,6 +32,11 @@ namespace AMDGPU { +// Return the intrinsic ID for some target-defined opcodes that behave like +// intrinsics. Can't use MachineInstr::getIntrinsicID() since that expects an +// actual generic instrinsic opcode. +unsigned getIntrinsicID(const MachineInstr &I); + struct RsrcIntrinsic { unsigned Intr; uint8_t RsrcArg; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.cpp @@ -14,6 +14,7 @@ #include "AMDGPUInstrInfo.h" #include "AMDGPU.h" +#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineMemOperand.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Instruction.h" @@ -26,6 +27,9 @@ AMDGPUInstrInfo::AMDGPUInstrInfo(const GCNSubtarget &ST) { } +unsigned AMDGPU::getIntrinsicID(const MachineInstr &I) { + return I.getOperand(I.getNumExplicitDefs()).getIntrinsicID(); +} // TODO: Should largely merge with AMDGPUTTIImpl::isSourceOfDivergence. bool AMDGPUInstrInfo::isUniformMMO(const MachineMemOperand *MMO) { diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -3457,8 +3457,8 @@ case AMDGPU::G_AMDGPU_INTRIN_IMAGE_LOAD_D16: case AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE: case AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE_D16: { - const AMDGPU::ImageDimIntrinsicInfo *Intr - = AMDGPU::getImageDimIntrinsicInfo(I.getIntrinsicID()); + const AMDGPU::ImageDimIntrinsicInfo *Intr = + AMDGPU::getImageDimIntrinsicInfo(AMDGPU::getIntrinsicID(I)); assert(Intr && "not an image intrinsic with image pseudo"); return selectImageIntrinsic(I, Intr); } diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp @@ -3019,8 +3019,8 @@ case AMDGPU::G_AMDGPU_INTRIN_IMAGE_LOAD_D16: case AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE: case AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE_D16: { - const AMDGPU::RsrcIntrinsic *RSrcIntrin - = AMDGPU::lookupRsrcIntrinsic(MI.getIntrinsicID()); + const AMDGPU::RsrcIntrinsic *RSrcIntrin = + AMDGPU::lookupRsrcIntrinsic(AMDGPU::getIntrinsicID(MI)); assert(RSrcIntrin && RSrcIntrin->IsImage); // Non-images can have complications from operands that allow both SGPR // and VGPR. For now it's too complicated to figure out the final opcode @@ -4521,7 +4521,7 @@ case AMDGPU::G_AMDGPU_INTRIN_IMAGE_LOAD_D16: case AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE: case AMDGPU::G_AMDGPU_INTRIN_IMAGE_STORE_D16: { - auto IntrID = MI.getIntrinsicID(); + auto IntrID = AMDGPU::getIntrinsicID(MI); const AMDGPU::RsrcIntrinsic *RSrcIntrin = AMDGPU::lookupRsrcIntrinsic(IntrID); assert(RSrcIntrin && "missing RsrcIntrinsic for image intrinsic"); // Non-images can have complications from operands that allow both SGPR