/// ToAS is valid.
bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const;
+ /// Return false if a \p AS0 address cannot possibly alias a \p AS1 address.
+ bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const;
+
/// Returns the address space ID for a target's 'flat' address space. Note
/// this is not necessarily the same as addrspace(0), which LLVM sometimes
/// refers to as the generic address space. The flat address space is a
virtual bool isSourceOfDivergence(const Value *V) = 0;
virtual bool isAlwaysUniform(const Value *V) = 0;
virtual bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const = 0;
+ virtual bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const = 0;
virtual unsigned getFlatAddressSpace() = 0;
virtual bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
Intrinsic::ID IID) const = 0;
return Impl.isValidAddrSpaceCast(FromAS, ToAS);
}
+ bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const override {
+ return Impl.addrspacesMayAlias(AS0, AS1);
+ }
+
unsigned getFlatAddressSpace() override { return Impl.getFlatAddressSpace(); }
bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
return false;
}
+ bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const {
+ return true;
+ }
+
unsigned getFlatAddressSpace() const { return -1; }
bool collectFlatAddressOperands(SmallVectorImpl<int> &OpIndexes,
return false;
}
+ bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const {
+ return true;
+ }
+
unsigned getFlatAddressSpace() {
// Return an invalid address space.
return -1;
return TTIImpl->isValidAddrSpaceCast(FromAS, ToAS);
}
+bool llvm::TargetTransformInfo::addrspacesMayAlias(unsigned FromAS,
+ unsigned ToAS) const {
+ return TTIImpl->addrspacesMayAlias(FromAS, ToAS);
+}
+
unsigned TargetTransformInfo::getFlatAddressSpace() const {
return TTIImpl->getFlatAddressSpace();
}
AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT ||
AS > AMDGPUAS::MAX_AMDGPU_ADDRESS;
}
+
+static inline bool addrspacesMayAlias(unsigned AS1, unsigned AS2) {
+ static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 8, "Addr space out of range");
+
+ if (AS1 > AMDGPUAS::MAX_AMDGPU_ADDRESS || AS2 > AMDGPUAS::MAX_AMDGPU_ADDRESS)
+ return true;
+
+ // This array is indexed by address space value enum elements 0 ... to 8
+ // clang-format off
+ static const bool ASAliasRules[9][9] = {
+ /* Flat Global Region Group Constant Private Const32 BufFatPtr BufRsrc */
+ /* Flat */ {true, true, false, true, true, true, true, true, true},
+ /* Global */ {true, true, false, false, true, false, true, true, true},
+ /* Region */ {false, false, true, false, false, false, false, false, false},
+ /* Group */ {true, false, false, true, false, false, false, false, false},
+ /* Constant */ {true, true, false, false, false, false, true, true, true},
+ /* Private */ {true, false, false, false, false, true, false, false, false},
+ /* Constant 32-bit */ {true, true, false, false, true, false, false, true, true},
+ /* Buffer Fat Ptr */ {true, true, false, false, true, false, true, true, true},
+ /* Buffer Resource */ {true, true, false, false, true, false, true, true, true},
+ };
+ // clang-format on
+
+ return ASAliasRules[AS1][AS2];
+}
+
}
} // End namespace llvm
AU.setPreservesAll();
}
-static AliasResult getAliasResult(unsigned AS1, unsigned AS2) {
- static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 8, "Addr space out of range");
-
- if (AS1 > AMDGPUAS::MAX_AMDGPU_ADDRESS || AS2 > AMDGPUAS::MAX_AMDGPU_ADDRESS)
- return AliasResult::MayAlias;
-
-#define ASMay AliasResult::MayAlias
-#define ASNo AliasResult::NoAlias
- // This array is indexed by address space value enum elements 0 ... to 8
- // clang-format off
- static const AliasResult ASAliasRules[9][9] = {
- /* Flat Global Region Group Constant Private Const32 BufFatPtr BufRsrc */
- /* Flat */ {ASMay, ASMay, ASNo, ASMay, ASMay, ASMay, ASMay, ASMay, ASMay},
- /* Global */ {ASMay, ASMay, ASNo, ASNo, ASMay, ASNo, ASMay, ASMay, ASMay},
- /* Region */ {ASNo, ASNo, ASMay, ASNo, ASNo, ASNo, ASNo, ASNo, ASNo},
- /* Group */ {ASMay, ASNo, ASNo, ASMay, ASNo, ASNo, ASNo, ASNo, ASNo},
- /* Constant */ {ASMay, ASMay, ASNo, ASNo, ASNo, ASNo, ASMay, ASMay, ASMay},
- /* Private */ {ASMay, ASNo, ASNo, ASNo, ASNo, ASMay, ASNo, ASNo, ASNo},
- /* Constant 32-bit */ {ASMay, ASMay, ASNo, ASNo, ASMay, ASNo, ASNo, ASMay, ASMay},
- /* Buffer Fat Ptr */ {ASMay, ASMay, ASNo, ASNo, ASMay, ASNo, ASMay, ASMay, ASMay},
- /* Buffer Resource */ {ASMay, ASMay, ASNo, ASNo, ASMay, ASNo, ASMay, ASMay, ASMay},
- };
- // clang-format on
-#undef ASMay
-#undef ASNo
-
- return ASAliasRules[AS1][AS2];
-}
-
AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
const MemoryLocation &LocB, AAQueryInfo &AAQI,
const Instruction *) {
unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
- AliasResult Result = getAliasResult(asA, asB);
- if (Result == AliasResult::NoAlias)
- return Result;
+ if (!AMDGPU::addrspacesMayAlias(asA, asB))
+ return AliasResult::NoAlias;
// In general, FLAT (generic) pointers could be aliased to LOCAL or PRIVATE
// pointers. However, as LOCAL or PRIVATE pointers point to local objects, in
return false;
}
+ bool addrspacesMayAlias(unsigned AS0, unsigned AS1) const {
+ return AMDGPU::addrspacesMayAlias(AS0, AS1);
+ }
+
unsigned getFlatAddressSpace() const {
// Don't bother running InferAddressSpaces pass on graphics shaders which
// don't use flat addressing.