Index: include/llvm/IR/IntrinsicsAMDGPU.td =================================================================== --- include/llvm/IR/IntrinsicsAMDGPU.td +++ include/llvm/IR/IntrinsicsAMDGPU.td @@ -513,6 +513,11 @@ GCCBuiltin<"__builtin_amdgcn_lerp">, Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>; +// llvm.amdgcn.trap +def int_amdgcn_trap : + GCCBuiltin<"__builtin_amdgcn_trap">, + Intrinsic<[], [llvm_i32_ty], [IntrNoMem]>; + def int_amdgcn_sad_u8 : GCCBuiltin<"__builtin_amdgcn_sad_u8">, Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>; Index: lib/Target/AMDGPU/SOPInstructions.td =================================================================== --- lib/Target/AMDGPU/SOPInstructions.td +++ lib/Target/AMDGPU/SOPInstructions.td @@ -827,7 +827,9 @@ } // End Uses = [EXEC, M0] def S_SENDMSGHALT : SOPP <0x00000011, (ins SendMsgImm:$simm16), "s_sendmsghalt $simm16">; -def S_TRAP : SOPP <0x00000012, (ins i16imm:$simm16), "s_trap $simm16">; +def S_TRAP : SOPP <0x00000012, (ins i32imm:$simm16), "s_trap $simm16", + [(int_amdgcn_trap (i32 imm:$simm16))]>; + def S_ICACHE_INV : SOPP <0x00000013, (ins), "s_icache_inv"> { let simm16 = 0; } Index: test/CodeGen/AMDGPU/llvm.amdgcn.trap.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/llvm.amdgcn.trap.ll @@ -0,0 +1,13 @@ +; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s +; RUN: llc -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s + +declare void @llvm.amdgcn.trap(i32) #0 + +; GCN-LABEL: {{^}}s_trap_emit: +; GCN: s_trap +define void @s_trap_emit(i32 %x) nounwind { + call void @llvm.amdgcn.trap(i32 16) #0 + ret void +} + +attributes #0 = { nounwind readnone }