summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2014-07-01 22:10:30 +0000
committerTim Northover <tnorthover@apple.com>2014-07-01 22:10:30 +0000
commit334d8eebe5ef1e24764967d737a24945c980ac2c (patch)
tree08adfc5134b928bdc03b93e37873ac2afdf74915
parent3bd03c709930114405fca1eaaae1eef8b2be2d58 (diff)
downloadbcm5719-llvm-334d8eebe5ef1e24764967d737a24945c980ac2c.tar.gz
bcm5719-llvm-334d8eebe5ef1e24764967d737a24945c980ac2c.zip
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. llvm-svn: 212136
-rw-r--r--llvm/lib/Target/X86/X86AtomicExpandPass.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Target/X86/X86AtomicExpandPass.cpp b/llvm/lib/Target/X86/X86AtomicExpandPass.cpp
index 2ba76091f28..1637b55b6d3 100644
--- a/llvm/lib/Target/X86/X86AtomicExpandPass.cpp
+++ b/llvm/lib/Target/X86/X86AtomicExpandPass.cpp
@@ -90,6 +90,9 @@ bool X86AtomicExpandPass::runOnFunction(Function &F) {
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::expandAtomicRMW(AtomicRMWInst *AI) {
Builder.CreateCondBr(Success, ExitBB, LoopBB);
AI->replaceAllUsesWith(NewLoaded);
- AI->eraseFromParent();
return true;
}
@@ -268,10 +270,11 @@ bool X86AtomicExpandPass::expandAtomicStore(StoreInst *SI) {
// 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))
OpenPOWER on IntegriCloud