llvm.org GIT mirror llvm / 64444b4
AMDGPU: Change mubuf soffset register when SP relative Check the MachinePointerInfo for whether the access is supposed to be relative to the stack pointer. No tests because this is used in later commits implementing calls. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303301 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 3 years ago
2 changed file(s) with 55 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
8181 void PostprocessISelDAG() override;
8282
8383 private:
84 SDValue foldFrameIndex(SDValue N) const;
84 std::pair foldFrameIndex(SDValue N) const;
8585 bool isNoNanSrc(SDValue N) const;
8686 bool isInlineImmediate(const SDNode *N) const;
8787 bool FoldOperand(SDValue &Src, SDValue &Sel, SDValue &Neg, SDValue &Abs,
115115 bool SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc,
116116 SDValue &VAddr, SDValue &SOffset, SDValue &Offset,
117117 SDValue &SLC) const;
118 bool SelectMUBUFScratchOffen(SDValue Addr, SDValue &RSrc, SDValue &VAddr,
118 bool SelectMUBUFScratchOffen(SDNode *Root,
119 SDValue Addr, SDValue &RSrc, SDValue &VAddr,
119120 SDValue &SOffset, SDValue &ImmOffset) const;
120 bool SelectMUBUFScratchOffset(SDValue Addr, SDValue &SRsrc, SDValue &Soffset,
121 bool SelectMUBUFScratchOffset(SDNode *Root,
122 SDValue Addr, SDValue &SRsrc, SDValue &Soffset,
121123 SDValue &Offset) const;
122124
123125 bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &SOffset,
10731075 return SelectMUBUFAddr64(Addr, SRsrc, VAddr, SOffset, Offset, GLC, SLC, TFE);
10741076 }
10751077
1076 SDValue AMDGPUDAGToDAGISel::foldFrameIndex(SDValue N) const {
1077 if (auto FI = dyn_cast(N))
1078 return CurDAG->getTargetFrameIndex(FI->getIndex(), FI->getValueType(0));
1079 return N;
1080 }
1081
1082 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(SDValue Addr, SDValue &Rsrc,
1078 static bool isStackPtrRelative(const MachinePointerInfo &PtrInfo) {
1079 auto PSV = PtrInfo.V.dyn_cast();
1080 return PSV && PSV->isStack();
1081 }
1082
1083 std::pair AMDGPUDAGToDAGISel::foldFrameIndex(SDValue N) const {
1084 const MachineFunction &MF = CurDAG->getMachineFunction();
1085 const SIMachineFunctionInfo *Info = MF.getInfo();
1086
1087 if (auto FI = dyn_cast(N)) {
1088 SDValue TFI = CurDAG->getTargetFrameIndex(FI->getIndex(),
1089 FI->getValueType(0));
1090
1091 // If we can resolve this to a frame index access, this is relative to the
1092 // frame pointer SGPR.
1093 return std::make_pair(TFI, CurDAG->getRegister(Info->getFrameOffsetReg(),
1094 MVT::i32));
1095 }
1096
1097 // If we don't know this private access is a local stack object, it needs to
1098 // be relative to the entry point's scratch wave offset register.
1099 return std::make_pair(N, CurDAG->getRegister(Info->getScratchWaveOffsetReg(),
1100 MVT::i32));
1101 }
1102
1103 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(SDNode *Root,
1104 SDValue Addr, SDValue &Rsrc,
10831105 SDValue &VAddr, SDValue &SOffset,
10841106 SDValue &ImmOffset) const {
10851107
10881110 const SIMachineFunctionInfo *Info = MF.getInfo();
10891111
10901112 Rsrc = CurDAG->getRegister(Info->getScratchRSrcReg(), MVT::v4i32);
1091 SOffset = CurDAG->getRegister(Info->getScratchWaveOffsetReg(), MVT::i32);
10921113
10931114 if (ConstantSDNode *CAddr = dyn_cast(Addr)) {
10941115 unsigned Imm = CAddr->getZExtValue();
10991120 MachineSDNode *MovHighBits = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
11001121 DL, MVT::i32, HighBits);
11011122 VAddr = SDValue(MovHighBits, 0);
1123
1124 // In a call sequence, stores to the argument stack area are relative to the
1125 // stack pointer.
1126 const MachinePointerInfo &PtrInfo = cast(Root)->getPointerInfo();
1127 unsigned SOffsetReg = isStackPtrRelative(PtrInfo) ?
1128 Info->getStackPtrOffsetReg() : Info->getScratchWaveOffsetReg();
1129
1130 SOffset = CurDAG->getRegister(SOffsetReg, MVT::i32);
11021131 ImmOffset = CurDAG->getTargetConstant(Imm & 4095, DL, MVT::i16);
11031132 return true;
11041133 }
11121141 // Offsets in vaddr must be positive.
11131142 ConstantSDNode *C1 = cast(N1);
11141143 if (isLegalMUBUFImmOffset(C1)) {
1115 VAddr = foldFrameIndex(N0);
1144 std::tie(VAddr, SOffset) = foldFrameIndex(N0);
11161145 ImmOffset = CurDAG->getTargetConstant(C1->getZExtValue(), DL, MVT::i16);
11171146 return true;
11181147 }
11191148 }
11201149
11211150 // (node)
1122 VAddr = foldFrameIndex(Addr);
1151 std::tie(VAddr, SOffset) = foldFrameIndex(Addr);
11231152 ImmOffset = CurDAG->getTargetConstant(0, DL, MVT::i16);
11241153 return true;
11251154 }
11261155
1127 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffset(SDValue Addr,
1156 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffset(SDNode *Root,
1157 SDValue Addr,
11281158 SDValue &SRsrc,
11291159 SDValue &SOffset,
11301160 SDValue &Offset) const {
11371167 const SIMachineFunctionInfo *Info = MF.getInfo();
11381168
11391169 SRsrc = CurDAG->getRegister(Info->getScratchRSrcReg(), MVT::v4i32);
1140 SOffset = CurDAG->getRegister(Info->getScratchWaveOffsetReg(), MVT::i32);
1170
1171 const MachinePointerInfo &PtrInfo = cast(Root)->getPointerInfo();
1172 unsigned SOffsetReg = isStackPtrRelative(PtrInfo) ?
1173 Info->getStackPtrOffsetReg() : Info->getScratchWaveOffsetReg();
1174
1175 // FIXME: Get from MachinePointerInfo? We should only be using the frame
1176 // offset if we know this is in a call sequence.
1177 SOffset = CurDAG->getRegister(SOffsetReg, MVT::i32);
1178
11411179 Offset = CurDAG->getTargetConstant(CAddr->getZExtValue(), DL, MVT::i16);
11421180 return true;
11431181 }
1010 def MUBUFAddr64 : ComplexPattern;
1111 def MUBUFAddr64Atomic : ComplexPattern;
1212
13 def MUBUFScratchOffen : ComplexPattern;
14 def MUBUFScratchOffset : ComplexPattern>;
13 def MUBUFScratchOffen : ComplexPattern>;
14 def MUBUFScratchOffset : ComplexPattern;
1515
1616 def MUBUFOffset : ComplexPattern;
1717 def MUBUFOffsetNoGLC : ComplexPattern;