Index: include/llvm/CodeGen/SelectionDAGNodes.h =================================================================== --- include/llvm/CodeGen/SelectionDAGNodes.h +++ include/llvm/CodeGen/SelectionDAGNodes.h @@ -66,6 +66,7 @@ class SelectionDAG; class Type; class Value; +class AtomicSDNode; //forward declare for type check void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr, bool force = false); @@ -1287,6 +1288,7 @@ return Data; } + bool isAtomic() const { return isa(this); } bool isVolatile() const { return MemSDNodeBits.IsVolatile; } bool isNonTemporal() const { return MemSDNodeBits.IsNonTemporal; } bool isDereferenceable() const { return MemSDNodeBits.IsDereferenceable; } Index: lib/CodeGen/MachineInstr.cpp =================================================================== --- lib/CodeGen/MachineInstr.cpp +++ lib/CodeGen/MachineInstr.cpp @@ -1305,6 +1305,7 @@ for (MachineMemOperand *MMO : memoperands()) { if (MMO->isVolatile()) return false; + if (MMO->isAtomic()) return false; if (MMO->isStore()) return false; if (MMO->isInvariant() && MMO->isDereferenceable()) continue; Index: lib/CodeGen/MachinePipeliner.cpp =================================================================== --- lib/CodeGen/MachinePipeliner.cpp +++ lib/CodeGen/MachinePipeliner.cpp @@ -2766,7 +2766,8 @@ return; SmallVector NewMMOs; for (MachineMemOperand *MMO : NewMI.memoperands()) { - if (MMO->isVolatile() || (MMO->isInvariant() && MMO->isDereferenceable()) || + if (MMO->isVolatile() || MMO->isAtomic() || + (MMO->isInvariant() && MMO->isDereferenceable()) || (!MMO->getValue())) { NewMMOs.push_back(MMO); continue; Index: lib/CodeGen/ScheduleDAGInstrs.cpp =================================================================== --- lib/CodeGen/ScheduleDAGInstrs.cpp +++ lib/CodeGen/ScheduleDAGInstrs.cpp @@ -131,7 +131,7 @@ const DataLayout &DL) { auto allMMOsOkay = [&]() { for (const MachineMemOperand *MMO : MI->memoperands()) { - if (MMO->isVolatile()) + if (MMO->isVolatile() || MMO->isAtomic()) return false; if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) { Index: lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -4180,7 +4180,8 @@ int LdWidth = LdVT.getSizeInBits(); int WidthDiff = WidenWidth - LdWidth; - unsigned LdAlign = LD->isVolatile() ? 0 : Align; // Allow wider loads. + // Allow wider loads. + unsigned LdAlign = (LD->isVolatile() || LD->isAtomic()) ? 0 : Align; // Find the vector type that can load from. EVT NewVT = FindMemType(DAG, TLI, LdWidth, WidenVT, LdAlign, WidthDiff); Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -8829,7 +8829,7 @@ // Loads don't have side effects, look through them. if (LoadSDNode *Ld = dyn_cast(*this)) { - if (!Ld->isVolatile()) + if (!Ld->isVolatile() && !Ld->isAtomic()) return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth-1); } return false; @@ -8980,6 +8980,8 @@ int Dist) const { if (LD->isVolatile() || Base->isVolatile()) return false; + if (LD->isAtomic() || Base->isAtomic()) + return false; if (LD->isIndexed() || Base->isIndexed()) return false; if (LD->getChain() != Base->getChain()) Index: lib/CodeGen/SelectionDAG/TargetLowering.cpp =================================================================== --- lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -2379,7 +2379,7 @@ LoadSDNode *Lod = cast(N0.getOperand(0)); APInt bestMask; unsigned bestWidth = 0, bestOffset = 0; - if (!Lod->isVolatile() && Lod->isUnindexed()) { + if (!Lod->isVolatile() && !Lod->isAtomic() && Lod->isUnindexed()) { unsigned origWidth = N0.getValueSizeInBits(); unsigned maskWidth = origWidth; // We can narrow (e.g.) 16-bit extending loads on 32-bit target to