[llvm-branch-commits] [llvm] [AMDGPU] Use ds_append and ds_consume for unused LDS counter atomics (PR #234035)
Jay Foad via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 4 04:11:20 PST 2026
================
@@ -182,10 +190,55 @@ static bool isLegalCrossLaneType(Type *Ty) {
}
}
+bool AMDGPUAtomicOptimizerImpl::isDSAppendConsumeCandidate(
+ const AtomicRMWInst &I) const {
+ if (!I.use_empty())
+ return false;
+
+ // ds_append and ds_consume add 1 or -1 per active lane to a 32 bit value.
+ const auto *Val = dyn_cast<ConstantInt>(I.getValOperand());
+ if (I.getOperation() != AtomicRMWInst::Add || !I.getType()->isIntegerTy(32) ||
+ !Val || !(Val->isOne() || Val->isMinusOne()))
+ return false;
+
+ // This pass runs before AtomicExpand, so the intrinsic must be 4 byte
+ // aligned. The intrinsic also carries no memory ordering.
+ if (I.getPointerAddressSpace() != AMDGPUAS::LOCAL_ADDRESS ||
+ I.getAlign() < Align(4) || I.getOrdering() != AtomicOrdering::Monotonic)
+ return false;
+
+ // M0 holds a single address for the whole wave.
----------------
jayfoad wrote:
Agreed, LDS addressing never uses m0, only GDS does.
https://github.com/llvm/llvm-project/pull/234035
More information about the llvm-branch-commits
mailing list