Skip to content

Commit 206b5af

Browse files
authored
AtomicExpand: Allow incrementally legalizing atomicrmw (#103371)
If a lowering changed control flow, resume the legalization loop at the first newly inserted block. This will allow incrementally legalizing atomicrmw and cmpxchg. The AArch64 test might be a bugfix. Previously it would lower the vector FP case as a cmpxchg loop, but cmpxchgs get lowered but previously weren't. Maybe it shouldn't be reporting cmpxchg for the expand type in the first place though.
1 parent b4d9c52 commit 206b5af

File tree

5 files changed

+836
-691
lines changed

5 files changed

+836
-691
lines changed

llvm/lib/CodeGen/AtomicExpandPass.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,30 @@ bool AtomicExpandImpl::run(Function &F, const TargetMachine *TM) {
351351

352352
bool MadeChange = false;
353353

354-
SmallVector<Instruction *, 1> AtomicInsts;
355-
356-
// Changing control-flow while iterating through it is a bad idea, so gather a
357-
// list of all atomic instructions before we start.
358-
for (Instruction &I : instructions(F))
359-
if (I.isAtomic() && !isa<FenceInst>(&I))
360-
AtomicInsts.push_back(&I);
361-
362-
for (auto *I : AtomicInsts) {
363-
if (processAtomicInstr(I))
364-
MadeChange = true;
354+
for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE;) {
355+
BasicBlock *BB = &*BBI;
356+
++BBI;
357+
358+
BasicBlock::iterator Next;
359+
360+
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;
361+
I = Next) {
362+
Instruction &Inst = *I;
363+
Next = std::next(I);
364+
365+
if (processAtomicInstr(&Inst)) {
366+
MadeChange = true;
367+
368+
// Detect control flow change and resume iteration from the original
369+
// block to inspect any newly inserted blocks. This allows incremental
370+
// legalizaton of atomicrmw and cmpxchg.
371+
if (BB != Next->getParent()) {
372+
BBI = BB->getIterator();
373+
BBE = F.end();
374+
break;
375+
}
376+
}
377+
}
365378
}
366379

367380
return MadeChange;

0 commit comments

Comments
 (0)