@@ -705,15 +705,15 @@ void diagnoseUnknownMMRAASName(const MachineInstr &MI, StringRef AS) {
705705}
706706
707707// / Reads \p MI's MMRAs to parse the "amdgpu-synchronize-as" MMRA.
708- // / If this tag isn't present, or if it has no meaningful values, returns \p
709- // / Default. Otherwise returns all the address spaces concerned by the MMRA .
710- static SIAtomicAddrSpace getFenceAddrSpaceMMRA ( const MachineInstr &MI,
711- SIAtomicAddrSpace Default ) {
708+ // / If this tag isn't present, or if it has no meaningful values, returns
709+ // / \p none, otherwise returns the address spaces specified by the MD .
710+ static std::optional< SIAtomicAddrSpace>
711+ getSynchronizeAddrSpaceMD ( const MachineInstr &MI ) {
712712 static constexpr StringLiteral FenceASPrefix = " amdgpu-synchronize-as" ;
713713
714714 auto MMRA = MMRAMetadata (MI.getMMRAMetadata ());
715715 if (!MMRA)
716- return Default ;
716+ return std:: nullopt ;
717717
718718 SIAtomicAddrSpace Result = SIAtomicAddrSpace::NONE;
719719 for (const auto &[Prefix, Suffix] : MMRA) {
@@ -726,7 +726,10 @@ static SIAtomicAddrSpace getFenceAddrSpaceMMRA(const MachineInstr &MI,
726726 diagnoseUnknownMMRAASName (MI, Suffix);
727727 }
728728
729- return (Result != SIAtomicAddrSpace::NONE) ? Result : Default;
729+ if (Result == SIAtomicAddrSpace::NONE)
730+ return std::nullopt ;
731+
732+ return Result;
730733}
731734
732735} // end anonymous namespace
@@ -903,12 +906,19 @@ SIMemOpAccess::getAtomicFenceInfo(const MachineBasicBlock::iterator &MI) const {
903906 std::tie (Scope, OrderingAddrSpace, IsCrossAddressSpaceOrdering) =
904907 *ScopeOrNone;
905908
906- if ((OrderingAddrSpace == SIAtomicAddrSpace::NONE) ||
907- ((OrderingAddrSpace & SIAtomicAddrSpace::ATOMIC) != OrderingAddrSpace)) {
909+ if (OrderingAddrSpace != SIAtomicAddrSpace::ATOMIC) {
910+ // We currently expect refineOrderingAS to be the only place that
911+ // can refine the AS ordered by the fence.
912+ // If that changes, we need to review the semantics of that function
913+ // in case it needs to preserve certain address spaces.
908914 reportUnsupported (MI, " Unsupported atomic address space" );
909915 return std::nullopt ;
910916 }
911917
918+ auto SynchronizeAS = getSynchronizeAddrSpaceMD (*MI);
919+ if (SynchronizeAS)
920+ OrderingAddrSpace = *SynchronizeAS;
921+
912922 return SIMemOpInfo (Ordering, Scope, OrderingAddrSpace, SIAtomicAddrSpace::ATOMIC,
913923 IsCrossAddressSpaceOrdering, AtomicOrdering::NotAtomic);
914924}
@@ -2687,11 +2697,7 @@ bool SIMemoryLegalizer::expandAtomicFence(const SIMemOpInfo &MOI,
26872697 AtomicPseudoMIs.push_back (MI);
26882698 bool Changed = false ;
26892699
2690- // Refine fenced address space based on MMRAs.
2691- //
2692- // TODO: Should we support this MMRA on other atomic operations?
2693- auto OrderingAddrSpace =
2694- getFenceAddrSpaceMMRA (*MI, MOI.getOrderingAddrSpace ());
2700+ const SIAtomicAddrSpace OrderingAddrSpace = MOI.getOrderingAddrSpace ();
26952701
26962702 if (MOI.isAtomic ()) {
26972703 const AtomicOrdering Order = MOI.getOrdering ();
0 commit comments