Skip to content

Commit a58218c

Browse files
committed
Use shared helper
1 parent 29ade41 commit a58218c

File tree

4 files changed

+26
-36
lines changed

4 files changed

+26
-36
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17795,21 +17795,8 @@ atomicSupportedIfLegalIntType(const AtomicRMWInst *RMW) {
1779517795
static bool flatInstrMayAccessPrivate(const Instruction *I) {
1779617796
const MDNode *NoaliasAddrSpaceMD =
1779717797
I->getMetadata(LLVMContext::MD_noalias_addrspace);
17798-
if (!NoaliasAddrSpaceMD)
17799-
return true;
17800-
17801-
for (unsigned I = 0, E = NoaliasAddrSpaceMD->getNumOperands() / 2; I != E;
17802-
++I) {
17803-
auto *Low = mdconst::extract<ConstantInt>(
17804-
NoaliasAddrSpaceMD->getOperand(2 * I + 0));
17805-
if (Low->getValue().uge(AMDGPUAS::PRIVATE_ADDRESS)) {
17806-
auto *High = mdconst::extract<ConstantInt>(
17807-
NoaliasAddrSpaceMD->getOperand(2 * I + 1));
17808-
return High->getValue().ule(AMDGPUAS::PRIVATE_ADDRESS);
17809-
}
17810-
}
17811-
17812-
return true;
17798+
return !AMDGPU::hasValueInRange(NoaliasAddrSpaceMD,
17799+
AMDGPUAS::PRIVATE_ADDRESS);
1781317800
}
1781417801

1781517802
TargetLowering::AtomicExpansionKind

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,24 +4250,6 @@ bool SIInstrInfo::isAlwaysGDS(uint16_t Opcode) const {
42504250
Opcode == AMDGPU::DS_SUB_GS_REG_RTN || isGWS(Opcode);
42514251
}
42524252

4253-
static bool hasNoAliasAddrSpaceScratch(const MachineMemOperand *MemOp) {
4254-
const MDNode *MD = MemOp->getAAInfo().NoAliasAddrSpace;
4255-
if (!MD)
4256-
return false;
4257-
4258-
// This MD is structured in ranges [A, B)
4259-
// Check if PRIVATE is included in any of them.
4260-
for (unsigned I = 0, E = MD->getNumOperands() / 2; I != E; ++I) {
4261-
auto *Low = mdconst::extract<ConstantInt>(MD->getOperand(2 * I + 0));
4262-
auto *High = mdconst::extract<ConstantInt>(MD->getOperand(2 * I + 1));
4263-
if (Low->getValue().ule(AMDGPUAS::PRIVATE_ADDRESS) &&
4264-
High->getValue().ugt(AMDGPUAS::PRIVATE_ADDRESS))
4265-
return true;
4266-
}
4267-
4268-
return false;
4269-
}
4270-
42714253
bool SIInstrInfo::mayAccessScratchThroughFlat(const MachineInstr &MI) const {
42724254
if (!isFLAT(MI) || isFLATGlobal(MI))
42734255
return false;
@@ -4285,13 +4267,12 @@ bool SIInstrInfo::mayAccessScratchThroughFlat(const MachineInstr &MI) const {
42854267
if (MI.memoperands_empty())
42864268
return true;
42874269

4288-
// TODO (?): Does this need to be taught how to read noalias.addrspace ?
4289-
42904270
// See if any memory operand specifies an address space that involves scratch.
42914271
return any_of(MI.memoperands(), [](const MachineMemOperand *Memop) {
42924272
unsigned AS = Memop->getAddrSpace();
42934273
if (AS == AMDGPUAS::FLAT_ADDRESS)
4294-
return !hasNoAliasAddrSpaceScratch(Memop);
4274+
return !AMDGPU::hasValueInRange(Memop->getAAInfo().NoAliasAddrSpace,
4275+
AMDGPUAS::PRIVATE_ADDRESS);
42954276
return AS == AMDGPUAS::PRIVATE_ADDRESS;
42964277
});
42974278
}

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/IR/IntrinsicsAMDGPU.h"
2222
#include "llvm/IR/IntrinsicsR600.h"
2323
#include "llvm/IR/LLVMContext.h"
24+
#include "llvm/IR/Metadata.h"
2425
#include "llvm/MC/MCInstrInfo.h"
2526
#include "llvm/MC/MCRegisterInfo.h"
2627
#include "llvm/MC/MCSubtargetInfo.h"
@@ -1677,6 +1678,22 @@ getIntegerVecAttribute(const Function &F, StringRef Name, unsigned Size) {
16771678
return Vals;
16781679
}
16791680

1681+
bool hasValueInRange(const MDNode *MD, unsigned Val) {
1682+
if (!MD)
1683+
return false;
1684+
1685+
assert((MD->getNumOperands() % 2 == 0) && "invalid number of operands!");
1686+
for (unsigned I = 0, E = MD->getNumOperands() / 2; I != E; ++I) {
1687+
auto *Low = mdconst::extract<ConstantInt>(MD->getOperand(2 * I + 0));
1688+
auto *High = mdconst::extract<ConstantInt>(MD->getOperand(2 * I + 1));
1689+
assert(Low->getValue().ult(High->getValue()) && "invalid range metadata!");
1690+
if (Low->getValue().ule(Val) && High->getValue().ugt(Val))
1691+
return true;
1692+
}
1693+
1694+
return false;
1695+
}
1696+
16801697
unsigned getVmcntBitMask(const IsaVersion &Version) {
16811698
return (1 << (getVmcntBitWidthLo(Version.Major) +
16821699
getVmcntBitWidthHi(Version.Major))) -

llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MCInstrInfo;
3535
class MCRegisterClass;
3636
class MCRegisterInfo;
3737
class MCSubtargetInfo;
38+
class MDNode;
3839
class StringRef;
3940
class Triple;
4041
class raw_ostream;
@@ -1064,6 +1065,10 @@ SmallVector<unsigned> getIntegerVecAttribute(const Function &F, StringRef Name,
10641065
std::optional<SmallVector<unsigned>>
10651066
getIntegerVecAttribute(const Function &F, StringRef Name, unsigned Size);
10661067

1068+
/// Checks if \p Val is inside \p MD, a !range-like metadata.
1069+
/// Returns false if \p MD is null.
1070+
bool hasValueInRange(const MDNode *MD, unsigned Val);
1071+
10671072
/// Represents the counter values to wait for in an s_waitcnt instruction.
10681073
///
10691074
/// Large values (including the maximum possible integer) can be used to

0 commit comments

Comments
 (0)