Index: include/llvm/IR/IntrinsicsAMDGPU.td =================================================================== --- include/llvm/IR/IntrinsicsAMDGPU.td +++ include/llvm/IR/IntrinsicsAMDGPU.td @@ -389,6 +389,16 @@ GCCBuiltin<"__builtin_amdgcn_lerp">, Intrinsic<[llvm_i32_ty], [llvm_i32_ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem]>; +// llvm.amdgcn.icmp +def int_amdgcn_icmp : + Intrinsic<[llvm_i64_ty], [llvm_anyint_ty, LLVMMatchType<0>, llvm_i32_ty], + [IntrNoMem, IntrConvergent]>; + +// llvm.amdgcn.fcmp +def int_amdgcn_fcmp : + Intrinsic<[llvm_i64_ty], [llvm_anyfloat_ty, LLVMMatchType<0>, llvm_i32_ty], + [IntrNoMem, IntrConvergent]>; + //===----------------------------------------------------------------------===// // CI+ Intrinsics //===----------------------------------------------------------------------===// Index: lib/Target/AMDGPU/AMDGPUISelLowering.h =================================================================== --- lib/Target/AMDGPU/AMDGPUISelLowering.h +++ lib/Target/AMDGPU/AMDGPUISelLowering.h @@ -228,6 +228,7 @@ DWORDADDR, FRACT, CLAMP, + SETCC, //this is setcc with the full mask result // SIN_HW, COS_HW - f32 for SI, 1 ULP max error, valid from -100 pi to 100 pi. // Denormals handled on some parts. Index: lib/Target/AMDGPU/AMDGPUISelLowering.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -2804,6 +2804,7 @@ NODE_NAME_CASE(RETURN) NODE_NAME_CASE(DWORDADDR) NODE_NAME_CASE(FRACT) + NODE_NAME_CASE(SETCC) NODE_NAME_CASE(CLAMP) NODE_NAME_CASE(COS_HW) NODE_NAME_CASE(SIN_HW) Index: lib/Target/AMDGPU/AMDGPUInstrInfo.td =================================================================== --- lib/Target/AMDGPU/AMDGPUInstrInfo.td +++ lib/Target/AMDGPU/AMDGPUInstrInfo.td @@ -137,6 +137,11 @@ // out = (src1 > src0) ? 1 : 0 def AMDGPUborrow : SDNode<"AMDGPUISD::BORROW", SDTIntBinOp, []>; +def AMDGPUSetCCOp : SDTypeProfile<1, 3, [ // setcc + SDTCisVT<0, i64>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT> +]>; + +def AMDGPUsetcc : SDNode<"AMDGPUISD::SETCC", AMDGPUSetCCOp>; def AMDGPUcvt_f32_ubyte0 : SDNode<"AMDGPUISD::CVT_F32_UBYTE0", SDTIntToFPOp, []>; Index: lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- lib/Target/AMDGPU/SIISelLowering.cpp +++ lib/Target/AMDGPU/SIISelLowering.cpp @@ -31,6 +31,7 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/SelectionDAG.h" +#include "llvm/CodeGen/Analysis.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Function.h" @@ -1901,6 +1902,16 @@ return DAG.getNode(AMDGPUISD::DIV_SCALE, DL, Op->getVTList(), Src0, Denominator, Numerator); } + case Intrinsic::amdgcn_icmp: + case Intrinsic::amdgcn_fcmp: { + ICmpInst::Predicate IcInput = + static_cast(Op.getConstantOperandVal(3)); + assert(ICmpInst::Predicate::FIRST_ICMP_PREDICATE <= IcInput && + IcInput < ICmpInst::Predicate::BAD_ICMP_PREDICATE); + ISD::CondCode CCOpcode = getICmpCondCode(IcInput); + return DAG.getNode(AMDGPUISD::SETCC, DL, VT, Op.getOperand(1), + Op.getOperand(2), DAG.getCondCode(CCOpcode)); + } default: return AMDGPUTargetLowering::LowerOperation(Op, DAG); } Index: lib/Target/AMDGPU/SIInstructions.td =================================================================== --- lib/Target/AMDGPU/SIInstructions.td +++ lib/Target/AMDGPU/SIInstructions.td @@ -2357,6 +2357,59 @@ (DS_SWIZZLE_B32 $src, (as_i16imm $offset16), (i1 0)) >; + +//===----------------------------------------------------------------------===// +// V_ICMPIntrinsic Pattern. +//===----------------------------------------------------------------------===// + +class ICMP_Pattern : Pat < + (AMDGPUsetcc vt:$src0, vt:$src1, cond), + (inst $src0, $src1) +>; + +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; + +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; +def : ICMP_Pattern ; + +class FCMP_Pattern : Pat < + (i64(AMDGPUsetcc (vt(VOP3Mods vt:$src0, i32:$src0_modifiers)), + (vt(VOP3Mods vt:$src1, i32:$src1_modifiers)), cond)), + (inst $src0_modifiers, $src0, $src1_modifiers, $src1, + DSTCLAMP.NONE, DSTOMOD.NONE) +>; + +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; + +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; +def : FCMP_Pattern ; + //===----------------------------------------------------------------------===// // SMRD Patterns //===----------------------------------------------------------------------===// Index: test/CodeGen/AMDGPU/llvm.amdgcn.fcmp.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/llvm.amdgcn.fcmp.ll @@ -0,0 +1,107 @@ +; 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 i64 @llvm.amdgcn.fcmp.f32(float, float, i32) #0 +declare i64 @llvm.amdgcn.fcmp.f64(double, double, i32) #0 + +; GCN-LABEL: {{^}}v_fcmp_f32_eq: +; GCN: v_cmp_eq_f32_e64 +define void @v_fcmp_f32_eq(i64 addrspace(1)* %out, float %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f32(float %src, float 100.00, i32 32) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f32_ne: +; GCN: v_cmp_neq_f32_e64 +define void @v_fcmp_f32_ne(i64 addrspace(1)* %out, float %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f32(float %src, float 100.00, i32 33) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f32_ogt: +; GCN: v_cmp_gt_f32_e64 +define void @v_fcmp_f32_ogt(i64 addrspace(1)* %out, float %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f32(float %src, float 100.00, i32 38) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f32_oge: +; GCN: v_cmp_ge_f32_e64 +define void @v_fcmp_f32_oge(i64 addrspace(1)* %out, float %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f32(float %src, float 100.00, i32 39) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f32_olt: +; GCN: v_cmp_lt_f32_e64 +define void @v_fcmp_f32_olt(i64 addrspace(1)* %out, float %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f32(float %src, float 100.00, i32 40) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f32_ole: +; GCN: v_cmp_le_f32_e64 +define void @v_fcmp_f32_ole(i64 addrspace(1)* %out, float %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f32(float %src, float 100.00, i32 41) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f64_eq: +; GCN: v_cmp_eq_f64_e64 +define void @v_fcmp_f64_eq(i64 addrspace(1)* %out, double %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f64(double %src, double 100.00, i32 32) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f64_ne: +; GCN: v_cmp_neq_f64_e64 +define void @v_fcmp_f64_ne(i64 addrspace(1)* %out, double %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f64(double %src, double 100.00, i32 33) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f64_ogt: +; GCN: v_cmp_gt_f64_e64 +define void @v_fcmp_f64_ogt(i64 addrspace(1)* %out, double %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f64(double %src, double 100.00, i32 38) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f64_oge: +; GCN: v_cmp_ge_f64_e64 +define void @v_fcmp_f64_oge(i64 addrspace(1)* %out, double %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f64(double %src, double 100.00, i32 39) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f64_olt: +; GCN: v_cmp_lt_f64_e64 +define void @v_fcmp_f64_olt(i64 addrspace(1)* %out, double %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f64(double %src, double 100.00, i32 40) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_fcmp_f64_ole: +; GCN: v_cmp_le_f64_e64 +define void @v_fcmp_f64_ole(i64 addrspace(1)* %out, double %src) #1 { + %result = call i64 @llvm.amdgcn.fcmp.f64(double %src, double 100.00, i32 41) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + + + + +attributes #0 = { nounwind readnone convergent } +attributes #1 = { nounwind } Index: test/CodeGen/AMDGPU/llvm.amdgcn.icmp.ll =================================================================== --- /dev/null +++ test/CodeGen/AMDGPU/llvm.amdgcn.icmp.ll @@ -0,0 +1,166 @@ +; 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 i64 @llvm.amdgcn.icmp.i32(i32, i32, i32) #0 +declare i64 @llvm.amdgcn.icmp.i64(i64, i64, i32) #0 + +; GCN-LABEL: {{^}}v_icmp_i32_eq: +; GCN: v_cmp_eq_i32_e64 +define void @v_icmp_i32_eq(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 32) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_ne: +; GCN: v_cmp_ne_i32_e64 +define void @v_icmp_i32_ne(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 33) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_ugt: +; GCN: v_cmp_gt_i32_e64 +define void @v_icmp_i32_ugt(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 34) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_uge: +; GCN: v_cmp_ge_i32_e64 +define void @v_icmp_i32_uge(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 35) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_ult: +; GCN: v_cmp_lt_i32_e64 +define void @v_icmp_i32_ult(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 36) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_ule: +; GCN: v_cmp_le_i32_e64 +define void @v_icmp_i32_ule(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 37) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_sgt: +; GCN: v_cmp_gt_i32_e64 +define void @v_icmp_i32_sgt(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 38) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_sge: +; GCN: v_cmp_ge_i32_e64 +define void @v_icmp_i32_sge(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 39) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i32_slt: +; GCN: v_cmp_lt_i32_e64 +define void @v_icmp_i32_slt(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 40) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} +; GCN-LABEL: {{^}}v_icmp_i32_sle: +; GCN: v_cmp_le_i32_e64 +define void @v_icmp_i32_sle(i64 addrspace(1)* %out, i32 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i32(i32 %src, i32 100, i32 41) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_eq: +; GCN: v_cmp_eq_i64_e64 +define void @v_icmp_i64_eq(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 32) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_ne: +; GCN: v_cmp_ne_i64_e64 +define void @v_icmp_i64_ne(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 33) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_ugt: +; GCN: v_cmp_gt_i64_e64 +define void @v_icmp_i64_ugt(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 34) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_uge: +; GCN: v_cmp_ge_i64_e64 +define void @v_icmp_i64_uge(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 35) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_ult: +; GCN: v_cmp_lt_i64_e64 +define void @v_icmp_i64_ult(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 36) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_ule: +; GCN: v_cmp_le_i64_e64 +define void @v_icmp_i64_ule(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 37) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_sgt: +; GCN: v_cmp_gt_i64_e64 +define void @v_icmp_i64_sgt(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 38) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_sge: +; GCN: v_cmp_ge_i64_e64 +define void @v_icmp_i64_sge(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 39) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +; GCN-LABEL: {{^}}v_icmp_i64_slt: +; GCN: v_cmp_lt_i64_e64 +define void @v_icmp_i64_slt(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 40) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} +; GCN-LABEL: {{^}}v_icmp_i64_sle: +; GCN: v_cmp_le_i64_e64 +define void @v_icmp_i64_sle(i64 addrspace(1)* %out, i64 %src) #1 { + %result = call i64 @llvm.amdgcn.icmp.i64(i64 %src, i64 100, i32 41) + store i64 %result, i64 addrspace(1)* %out, align 4 + ret void +} + +attributes #0 = { nounwind readnone convergent } +attributes #1 = { nounwind }