[llvm] Attributor: Infer noalias.addrspace metadata for memory instructions (PR #136553)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 18:39:02 PDT 2025
================
@@ -12786,6 +12788,193 @@ struct AAAddressSpaceCallSiteArgument final : AAAddressSpaceImpl {
};
} // namespace
+/// ------------------------ No Alias Address Space ---------------------------
+// This attribute assumes flat address space can alias all other address space
+namespace {
+struct AANoAliasAddrSpaceImpl : public AANoAliasAddrSpace {
+ AANoAliasAddrSpaceImpl(const IRPosition &IRP, Attributor &A)
+ : AANoAliasAddrSpace(IRP, A) {}
+
+ void initialize(Attributor &A) override {
+ assert(getAssociatedType()->isPtrOrPtrVectorTy() &&
+ "Associated value is not a pointer");
+
+ resetASRanges(A);
+
+ std::optional<unsigned> FlatAS = A.getInfoCache().getFlatAddressSpace();
+ if (!FlatAS.has_value()) {
+ indicatePessimisticFixpoint();
+ return;
+ }
+
+ removeAS(*FlatAS);
+
+ unsigned AS = getAssociatedType()->getPointerAddressSpace();
+ if (AS != *FlatAS) {
+ removeAS(AS);
+ indicateOptimisticFixpoint();
+ }
+ }
+
+ ChangeStatus updateImpl(Attributor &A) override {
+ unsigned FlatAS = A.getInfoCache().getFlatAddressSpace().value();
+ uint32_t OldAssumed = getAssumed();
+
+ auto CheckAddressSpace = [&](Value &Obj) {
+ if (isa<PoisonValue>(&Obj))
+ return true;
+
+ unsigned AS = Obj.getType()->getPointerAddressSpace();
+ if (AS == FlatAS)
+ return false;
+
+ removeAS(Obj.getType()->getPointerAddressSpace());
+ return true;
+ };
+
+ const AAUnderlyingObjects *AUO = A.getOrCreateAAFor<AAUnderlyingObjects>(
+ getIRPosition(), this, DepClassTy::REQUIRED);
+ if (!AUO->forallUnderlyingObjects(CheckAddressSpace))
+ return indicatePessimisticFixpoint();
+
+ return OldAssumed == getAssumed() ? ChangeStatus::UNCHANGED
+ : ChangeStatus::CHANGED;
+ }
+
+ /// See AbstractAttribute::manifest(...).
+ ChangeStatus manifest(Attributor &A) override {
+ std::optional<unsigned> FlatAS = A.getInfoCache().getFlatAddressSpace();
----------------
shiltian wrote:
No need for the check. Directly use it like in `updateImpl`.
https://github.com/llvm/llvm-project/pull/136553
More information about the llvm-commits
mailing list