[llvm] r212136 - X86: remove atomic instructions *after* we've iterated through them.

Tim Northover tnorthover at apple.com
Tue Jul 1 15:10:30 PDT 2014


Author: tnorthover
Date: Tue Jul  1 17:10:30 2014
New Revision: 212136

URL: http://llvm.org/viewvc/llvm-project?rev=212136&view=rev
Log:
X86: remove atomic instructions *after* we've iterated through them.

Otherwise they get freed and the implicit "isa<XYZ>" tests following
turn out badly (at least under sanitizers).

Also corrects the ordering of unordered atomic stores.

Modified:
    llvm/trunk/lib/Target/X86/X86AtomicExpandPass.cpp

Modified: llvm/trunk/lib/Target/X86/X86AtomicExpandPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AtomicExpandPass.cpp?rev=212136&r1=212135&r2=212136&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AtomicExpandPass.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AtomicExpandPass.cpp Tue Jul  1 17:10:30 2014
@@ -90,6 +90,9 @@ bool X86AtomicExpandPass::runOnFunction(
       MadeChange |= expandAtomicRMW(AI);
     if (StoreInst *SI = dyn_cast<StoreInst>(Inst))
       MadeChange |= expandAtomicStore(SI);
+
+    assert(MadeChange && "Atomic inst not expanded when it should be?");
+    Inst->eraseFromParent();
   }
 
   return MadeChange;
@@ -259,7 +262,6 @@ bool X86AtomicExpandPass::expandAtomicRM
   Builder.CreateCondBr(Success, ExitBB, LoopBB);
 
   AI->replaceAllUsesWith(NewLoaded);
-  AI->eraseFromParent();
 
   return true;
 }
@@ -268,10 +270,11 @@ bool X86AtomicExpandPass::expandAtomicSt
   // An atomic store might need cmpxchg16b (or 8b on x86) to execute. Express
   // this in terms of the usual expansion to "atomicrmw xchg".
   IRBuilder<> Builder(SI);
+  AtomicOrdering Order =
+      SI->getOrdering() == Unordered ? Monotonic : SI->getOrdering();
   AtomicRMWInst *AI =
       Builder.CreateAtomicRMW(AtomicRMWInst::Xchg, SI->getPointerOperand(),
-                              SI->getValueOperand(), SI->getOrdering());
-  SI->eraseFromParent();
+                              SI->getValueOperand(), Order);
 
   // Now we have an appropriate swap instruction, lower it as usual.
   if (shouldExpandAtomicRMW(AI))





More information about the llvm-commits mailing list