diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -24039,6 +24039,16 @@ Optional(Size), LSN->getMemOperand()}; } + if (const auto *AN = dyn_cast(N)) { + // PRE_INC / PRE_DEC allegedly not a relevant issue, can set this to zero + int64_t Offset = 0; + uint64_t Size = + MemoryLocation::getSizeOrUnknown(AN->getMemoryVT().getStoreSize()); + return {AN->isVolatile(), AN->isAtomic(), AN->getBasePtr(), + Offset, + Optional(Size), + AN->getMemOperand()}; + } if (const auto *LN = cast(N)) return {false /*isVolatile*/, /*isAtomic*/ false, LN->getOperand(1), (LN->hasOffset()) ? LN->getOffset() : 0, @@ -24198,6 +24208,20 @@ return false; } default: + if (auto *AC = dyn_cast(C.getNode())) { + if (AC->getOrdering() == AtomicOrdering::Monotonic) { + bool IsOpLoad = AC->getOpcode() == ISD::ATOMIC_LOAD; + if ((IsLoad && IsOpLoad) || !mayAlias(N, AC)) { + LLVM_DEBUG( + dbgs() << "ImproveChain of node went past a monotonic Atomic operation.\n Node: "; + N->dump(); + dbgs() << " Atomic: "; + AC->dump()); + C = C.getOperand(0); + return true; + } + } + } return false; } };