@@ -4117,6 +4117,17 @@ SDValue SITargetLowering::LowerCall(CallLoweringInfo &CLI,
41174117 InVals, /*IsThisReturn=*/false, SDValue());
41184118}
41194119
4120+ SDValue SITargetLowering::lowerFrameIndex(SDValue Op, SelectionDAG &DAG) const {
4121+ // Since address space information is lost here, we assume that an i64 frame
4122+ // index comes from an alloca in AS0.
4123+ SDLoc DL(Op);
4124+ auto *FI = cast<FrameIndexSDNode>(Op);
4125+ SDValue TFI = DAG.getFrameIndex(FI->getIndex(), MVT::i32);
4126+ return DAG.getAddrSpaceCast(DL, Op.getValueType(), TFI,
4127+ AMDGPUAS::PRIVATE_ADDRESS,
4128+ AMDGPUAS::FLAT_ADDRESS);
4129+ }
4130+
41204131// This is similar to the default implementation in ExpandDYNAMIC_STACKALLOC,
41214132// except for:
41224133// 1. Stack growth direction(default: downwards, AMDGPU: upwards), and
@@ -4129,13 +4140,27 @@ SDValue SITargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op,
41294140 SDLoc dl(Op);
41304141 EVT VT = Op.getValueType();
41314142 SDValue Chain = Op.getOperand(0);
4143+ SDValue Size = Op.getOperand(1);
4144+
4145+ // Since address space information is lost here, we assume that an i64 dynamic
4146+ // alloca comes from an alloca in AS0.
4147+ if (VT == MVT::i64) {
4148+ SDValue Align = Op.getOperand(2);
4149+ Size = DAG.getZExtOrTrunc(Size, dl, MVT::i32);
4150+ SDValue Ops[] = {Chain, Size, Align};
4151+ SDValue DynAlloc =
4152+ DAG.getNode(ISD::DYNAMIC_STACKALLOC, dl, {MVT::i32, MVT::Other}, Ops);
4153+ SDValue Cast = DAG.getAddrSpaceCast(
4154+ dl, VT, DynAlloc, AMDGPUAS::PRIVATE_ADDRESS, AMDGPUAS::FLAT_ADDRESS);
4155+ return DAG.getMergeValues({Cast, DynAlloc.getValue(1)}, dl);
4156+ }
4157+
41324158 Register SPReg = Info->getStackPtrOffsetReg();
41334159
41344160 // Chain the dynamic stack allocation so that it doesn't modify the stack
41354161 // pointer when other instructions are using the stack.
41364162 Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
41374163
4138- SDValue Size = Op.getOperand(1);
41394164 SDValue BaseAddr = DAG.getCopyFromReg(Chain, dl, SPReg, VT);
41404165 Align Alignment = cast<ConstantSDNode>(Op.getOperand(2))->getAlignValue();
41414166
@@ -6087,6 +6112,8 @@ SDValue SITargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
60876112 case ISD::SMUL_LOHI:
60886113 case ISD::UMUL_LOHI:
60896114 return lowerXMUL_LOHI(Op, DAG);
6115+ case ISD::FrameIndex:
6116+ return lowerFrameIndex(Op, DAG);
60906117 case ISD::DYNAMIC_STACKALLOC:
60916118 return LowerDYNAMIC_STACKALLOC(Op, DAG);
60926119 case ISD::STACKSAVE:
0 commit comments