From a915f005cd63fd111bbca510236a5163a7e83576 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Fri, 11 May 2018 05:44:16 +0000 Subject: [PATCH] AMDGPU/GlobalISel: Implement select() for 32-bit G_FPTOUI Reviewers: arsenm, nhaehnle Subscribers: kzhuravl, wdng, yaxunl, rovka, kristof.beyls, dstuttard, tpr, t-tye, llvm-commits Differential Revision: https://reviews.llvm.org/D45883 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332082 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AMDGPU/AMDGPUGISel.td | 4 +++ .../AMDGPU/AMDGPUInstructionSelector.cpp | 11 ++++++ lib/Target/AMDGPU/AMDGPUInstructionSelector.h | 3 ++ .../AMDGPU/GlobalISel/inst-select-fptoui.mir | 36 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 test/CodeGen/AMDGPU/GlobalISel/inst-select-fptoui.mir diff --git a/lib/Target/AMDGPU/AMDGPUGISel.td b/lib/Target/AMDGPU/AMDGPUGISel.td index 74b73de6d65..c9dfbafab0c 100644 --- a/lib/Target/AMDGPU/AMDGPUGISel.td +++ b/lib/Target/AMDGPU/AMDGPUGISel.td @@ -18,6 +18,10 @@ def gi_vsrc0 : GIComplexOperandMatcher, GIComplexPatternEquiv; +def gi_vop3mods0 : + GIComplexOperandMatcher, + GIComplexPatternEquiv; + class GISelSop2Pat < SDPatternOperator node, Instruction inst, diff --git a/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp b/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp index 085a9c2f6fa..52ecca76095 100644 --- a/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ b/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -455,6 +455,7 @@ bool AMDGPUInstructionSelector::select(MachineInstr &I, switch (I.getOpcode()) { default: break; + case TargetOpcode::G_FPTOUI: case TargetOpcode::G_OR: return selectImpl(I, CoverageInfo); case TargetOpcode::G_ADD: @@ -482,3 +483,13 @@ AMDGPUInstructionSelector::selectVSRC0(MachineOperand &Root) const { [=](MachineInstrBuilder &MIB) { MIB.add(Root); } }}; } + +InstructionSelector::ComplexRendererFns +AMDGPUInstructionSelector::selectVOP3Mods0(MachineOperand &Root) const { + return {{ + [=](MachineInstrBuilder &MIB) { MIB.add(Root); }, + [=](MachineInstrBuilder &MIB) { MIB.addImm(0); }, // src0_mods + [=](MachineInstrBuilder &MIB) { MIB.addImm(0); }, // clamp + [=](MachineInstrBuilder &MIB) { MIB.addImm(0); } // omod + }}; +} diff --git a/lib/Target/AMDGPU/AMDGPUInstructionSelector.h b/lib/Target/AMDGPU/AMDGPUInstructionSelector.h index f9ab4d0d68f..cdad743ff22 100644 --- a/lib/Target/AMDGPU/AMDGPUInstructionSelector.h +++ b/lib/Target/AMDGPU/AMDGPUInstructionSelector.h @@ -73,6 +73,9 @@ private: InstructionSelector::ComplexRendererFns selectVSRC0(MachineOperand &Root) const; + InstructionSelector::ComplexRendererFns + selectVOP3Mods0(MachineOperand &Root) const; + const SIInstrInfo &TII; const SIRegisterInfo &TRI; const AMDGPURegisterBankInfo &RBI; diff --git a/test/CodeGen/AMDGPU/GlobalISel/inst-select-fptoui.mir b/test/CodeGen/AMDGPU/GlobalISel/inst-select-fptoui.mir new file mode 100644 index 00000000000..07f19c4b34d --- /dev/null +++ b/test/CodeGen/AMDGPU/GlobalISel/inst-select-fptoui.mir @@ -0,0 +1,36 @@ +# RUN: llc -march=amdgcn -run-pass=instruction-select -verify-machineinstrs -global-isel %s -o - | FileCheck %s -check-prefixes=GCN + +--- | + define amdgpu_kernel void @fptoui(i32 addrspace(1)* %global0) {ret void} +... +--- + +name: fptoui +legalized: true +regBankSelected: true + +# GCN-LABEL: name: fptoui +body: | + bb.0: + liveins: $sgpr0, $vgpr0, $vgpr3_vgpr4 + + ; GCN: [[SGPR:%[0-9]+]]:sreg_32_xm0 = COPY $sgpr0 + %0:sgpr(s32) = COPY $sgpr0 + + ; GCN: [[VGPR:%[0-9]+]]:vgpr_32 = COPY $vgpr0 + %1:vgpr(s32) = COPY $vgpr0 + + %2:vgpr(s64) = COPY $vgpr3_vgpr4 + + ; fptoui s + ; GCN: V_CVT_U32_F32_e64 0, [[SGPR]], 0, 0 + %3:vgpr(s32) = G_FPTOUI %0 + + ; fptoui v + ; GCN: V_CVT_U32_F32_e64 0, [[VGPR]], 0, 0 + %4:vgpr(s32) = G_FPTOUI %1 + + G_STORE %3, %2 :: (store 4 into %ir.global0) + G_STORE %4, %2 :: (store 4 into %ir.global0) +... +---