[llvm] [IR][AtomicExpand] Add elementwise modifier to atomicrmw; automatically expand for all targets (PR #189517)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 08:20:11 PDT 2026


================
@@ -565,6 +602,45 @@ AtomicExpandImpl::convertAtomicXchgToIntegerType(AtomicRMWInst *RMWI) {
   return NewRMWI;
 }
 
+// Scalarize an elementwise vector atomicrmw into one scalar atomicrmw per
+// lane. Each lane keeps the original ordering/scope/volatility and is fed back
+// through processAtomicInstr() so the usual atomic expansion and fence logic
+// applies per lane rather than to the whole vector value.
+bool AtomicExpandImpl::expandElementwiseAtomicRMW(AtomicRMWInst *AI) {
+  auto *VecTy = cast<FixedVectorType>(AI->getType());
+  Type *LaneTy = VecTy->getElementType();
+  LLVMContext &Ctx = AI->getContext();
+  Value *Result = Constant::getNullValue(VecTy);
+  const uint64_t LaneSize = DL->getTypeStoreSize(LaneTy).getFixedValue();
+
+  for (unsigned Lane = 0, NumLanes = VecTy->getNumElements(); Lane != NumLanes;
+       ++Lane) {
+    ReplacementIRBuilder Builder(AI, *DL);
----------------
antoniofrighetto wrote:

Can hoist the builder out of the loop?

https://github.com/llvm/llvm-project/pull/189517


More information about the llvm-commits mailing list