Index: llvm/lib/Target/AMDGPU/AMDGPUGISel.td =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUGISel.td +++ llvm/lib/Target/AMDGPU/AMDGPUGISel.td @@ -317,3 +317,6 @@ def gi_extract_swz : GICustomOperandRenderer<"renderExtractSWZ">, GISDNodeXFormEquiv; + +def gi_frameindex_to_targetframeindex : GICustomOperandRenderer<"renderFrameIndex">, + GISDNodeXFormEquiv; Index: llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h +++ llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h @@ -133,7 +133,7 @@ bool selectG_STORE(MachineInstr &I) const; bool selectG_SELECT(MachineInstr &I) const; bool selectG_BRCOND(MachineInstr &I) const; - bool selectG_FRAME_INDEX_GLOBAL_VALUE(MachineInstr &I) const; + bool selectG_GLOBAL_VALUE(MachineInstr &I) const; bool selectG_PTRMASK(MachineInstr &I) const; bool selectG_EXTRACT_VECTOR_ELT(MachineInstr &I) const; bool selectG_INSERT_VECTOR_ELT(MachineInstr &I) const; @@ -286,6 +286,8 @@ int OpIdx) const; void renderExtractSWZ(MachineInstrBuilder &MIB, const MachineInstr &MI, int OpIdx) const; + void renderFrameIndex(MachineInstrBuilder &MIB, const MachineInstr &MI, + int OpIdx) const; bool isInlineImmediate16(int64_t Imm) const; bool isInlineImmediate32(int64_t Imm) const; Index: llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp @@ -2352,7 +2352,7 @@ return true; } -bool AMDGPUInstructionSelector::selectG_FRAME_INDEX_GLOBAL_VALUE( +bool AMDGPUInstructionSelector::selectG_GLOBAL_VALUE( MachineInstr &I) const { Register DstReg = I.getOperand(0).getReg(); const RegisterBank *DstRB = RBI.getRegBank(DstReg, *MRI, TRI); @@ -2903,9 +2903,8 @@ return selectG_SZA_EXT(I); case TargetOpcode::G_BRCOND: return selectG_BRCOND(I); - case TargetOpcode::G_FRAME_INDEX: case TargetOpcode::G_GLOBAL_VALUE: - return selectG_FRAME_INDEX_GLOBAL_VALUE(I); + return selectG_GLOBAL_VALUE(I); case TargetOpcode::G_PTRMASK: return selectG_PTRMASK(I); case TargetOpcode::G_EXTRACT_VECTOR_ELT: @@ -3884,6 +3883,12 @@ MIB.addImm((MI.getOperand(OpIdx).getImm() >> 3) & 1); } +void AMDGPUInstructionSelector::renderFrameIndex(MachineInstrBuilder &MIB, + const MachineInstr &MI, + int OpIdx) const { + MIB.addFrameIndex((MI.getOperand(1).getIndex())); +} + bool AMDGPUInstructionSelector::isInlineImmediate16(int64_t Imm) const { return AMDGPU::isInlinableLiteral16(Imm, STI.hasInv2PiInlineImm()); } Index: llvm/lib/Target/AMDGPU/SIInstructions.td =================================================================== --- llvm/lib/Target/AMDGPU/SIInstructions.td +++ llvm/lib/Target/AMDGPU/SIInstructions.td @@ -1499,8 +1499,13 @@ >; def : GCNPat < - (i32 frameindex:$fi), - (V_MOV_B32_e32 (i32 (frameindex_to_targetframeindex $fi))) + (p5 frameindex:$fi), + (V_MOV_B32_e32 (p5 (frameindex_to_targetframeindex $fi))) +>; + +def : GCNPat < + (p5 frameindex:$fi), + (S_MOV_B32 (p5 (frameindex_to_targetframeindex $fi))) >; def : GCNPat <