@@ -1322,37 +1322,37 @@ bool SITargetLowering::getAddrModeArguments(IntrinsicInst *II,
13221322 }
13231323}
13241324
1325- bool SITargetLowering::isLegalFlatAddressingMode(const AddrMode &AM) const {
1325+ bool SITargetLowering::isLegalFlatAddressingMode(const AddrMode &AM,
1326+ unsigned AddrSpace,
1327+ uint64_t FlatVariant) const {
13261328 if (!Subtarget->hasFlatInstOffsets()) {
13271329 // Flat instructions do not have offsets, and only have the register
13281330 // address.
13291331 return AM.BaseOffs == 0 && AM.Scale == 0;
13301332 }
13311333
13321334 return AM.Scale == 0 &&
1333- (AM.BaseOffs == 0 ||
1334- Subtarget->getInstrInfo()->isLegalFLATOffset(
1335- AM.BaseOffs, AMDGPUAS::FLAT_ADDRESS, SIInstrFlags::FLAT));
1335+ (AM.BaseOffs == 0 || Subtarget->getInstrInfo()->isLegalFLATOffset(
1336+ AM.BaseOffs, AddrSpace, FlatVariant));
13361337}
13371338
13381339bool SITargetLowering::isLegalGlobalAddressingMode(const AddrMode &AM) const {
13391340 if (Subtarget->hasFlatGlobalInsts())
1340- return AM.Scale == 0 &&
1341- (AM.BaseOffs == 0 || Subtarget->getInstrInfo()->isLegalFLATOffset(
1342- AM.BaseOffs, AMDGPUAS::GLOBAL_ADDRESS,
1343- SIInstrFlags::FlatGlobal));
1341+ return isLegalFlatAddressingMode(AM, AMDGPUAS::GLOBAL_ADDRESS,
1342+ SIInstrFlags::FlatGlobal);
13441343
13451344 if (!Subtarget->hasAddr64() || Subtarget->useFlatForGlobal()) {
1346- // Assume the we will use FLAT for all global memory accesses
1347- // on VI.
1348- // FIXME: This assumption is currently wrong. On VI we still use
1349- // MUBUF instructions for the r + i addressing mode. As currently
1350- // implemented, the MUBUF instructions only work on buffer < 4GB.
1351- // It may be possible to support > 4GB buffers with MUBUF instructions,
1352- // by setting the stride value in the resource descriptor which would
1353- // increase the size limit to (stride * 4GB). However, this is risky,
1354- // because it has never been validated.
1355- return isLegalFlatAddressingMode(AM);
1345+ // Assume the we will use FLAT for all global memory accesses
1346+ // on VI.
1347+ // FIXME: This assumption is currently wrong. On VI we still use
1348+ // MUBUF instructions for the r + i addressing mode. As currently
1349+ // implemented, the MUBUF instructions only work on buffer < 4GB.
1350+ // It may be possible to support > 4GB buffers with MUBUF instructions,
1351+ // by setting the stride value in the resource descriptor which would
1352+ // increase the size limit to (stride * 4GB). However, this is risky,
1353+ // because it has never been validated.
1354+ return isLegalFlatAddressingMode(AM, AMDGPUAS::FLAT_ADDRESS,
1355+ SIInstrFlags::FLAT);
13561356 }
13571357
13581358 return isLegalMUBUFAddressingMode(AM);
@@ -1449,7 +1449,10 @@ bool SITargetLowering::isLegalAddressingMode(const DataLayout &DL,
14491449 }
14501450
14511451 if (AS == AMDGPUAS::PRIVATE_ADDRESS)
1452- return isLegalMUBUFAddressingMode(AM);
1452+ return Subtarget->enableFlatScratch()
1453+ ? isLegalFlatAddressingMode(AM, AMDGPUAS::PRIVATE_ADDRESS,
1454+ SIInstrFlags::FlatScratch)
1455+ : isLegalMUBUFAddressingMode(AM);
14531456
14541457 if (AS == AMDGPUAS::LOCAL_ADDRESS ||
14551458 (AS == AMDGPUAS::REGION_ADDRESS && Subtarget->hasGDS())) {
@@ -1475,7 +1478,8 @@ bool SITargetLowering::isLegalAddressingMode(const DataLayout &DL,
14751478 // computation. We don't have instructions that compute pointers with any
14761479 // addressing modes, so treat them as having no offset like flat
14771480 // instructions.
1478- return isLegalFlatAddressingMode(AM);
1481+ return isLegalFlatAddressingMode(AM, AMDGPUAS::FLAT_ADDRESS,
1482+ SIInstrFlags::FLAT);
14791483 }
14801484
14811485 // Assume a user alias of global for unknown address spaces.
0 commit comments