Skip to content

Commit

Permalink
AtomicExpand: Allow incrementally legalizing atomicrmw (llvm#103371)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arsenm authored Aug 30, 2024
1 parent b4d9c52 commit 206b5af
Show file tree
Hide file tree
Showing 5 changed files with 836 additions and 691 deletions.
35 changes: 24 additions & 11 deletions llvm/lib/CodeGen/AtomicExpandPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,30 @@ bool AtomicExpandImpl::run(Function &F, const TargetMachine *TM) {

bool MadeChange = false;

SmallVector<Instruction *, 1> AtomicInsts;

// Changing control-flow while iterating through it is a bad idea, so gather a
// list of all atomic instructions before we start.
for (Instruction &I : instructions(F))
if (I.isAtomic() && !isa<FenceInst>(&I))
AtomicInsts.push_back(&I);

for (auto *I : AtomicInsts) {
if (processAtomicInstr(I))
MadeChange = true;
for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE;) {
BasicBlock *BB = &*BBI;
++BBI;

BasicBlock::iterator Next;

for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;
I = Next) {
Instruction &Inst = *I;
Next = std::next(I);

if (processAtomicInstr(&Inst)) {
MadeChange = true;

// Detect control flow change and resume iteration from the original
// block to inspect any newly inserted blocks. This allows incremental
// legalizaton of atomicrmw and cmpxchg.
if (BB != Next->getParent()) {
BBI = BB->getIterator();
BBE = F.end();
break;
}
}
}
}

return MadeChange;
Expand Down
Loading

0 comments on commit 206b5af

Please sign in to comment.