Skip to content

Commit

Permalink
[MIR-Canon] Fixing non-determinism that was breaking bots (NFC).
Browse files Browse the repository at this point in the history
An earlier fix of a subtle iterator invalidation bug had uncovered a
nondeterminism that was present in the MultiUsers bag. Problem was that
MultiUsers was being looked up using pointers.

This patch is an NFC change that numbers each multiuser and processes each in
numbered order. This fixes the test failure on netbsd and will likely fix the
green-dragon bot too.

llvm-svn: 363012
  • Loading branch information
plotfi committed Jun 11, 2019
1 parent cd0bc47 commit 4d89462
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
Expand Up @@ -180,6 +180,8 @@ static bool rescheduleCanonically(unsigned &PseudoIdempotentInstCount,
}

std::map<MachineInstr *, std::vector<MachineInstr *>> MultiUsers;
std::map<unsigned, MachineInstr *> MultiUserLookup;
unsigned UseToBringDefCloserToCount = 0;
std::vector<MachineInstr *> PseudoIdempotentInstructions;
std::vector<unsigned> PhysRegDefs;
for (auto *II : Instructions) {
Expand Down Expand Up @@ -255,6 +257,7 @@ static bool rescheduleCanonically(unsigned &PseudoIdempotentInstCount,
if (Delta < Distance) {
Distance = Delta;
UseToBringDefCloserTo = UseInst;
MultiUserLookup[UseToBringDefCloserToCount++] = UseToBringDefCloserTo;
}
}

Expand Down Expand Up @@ -294,19 +297,20 @@ static bool rescheduleCanonically(unsigned &PseudoIdempotentInstCount,
}

// Sort the defs for users of multiple defs lexographically.
for (const auto &E : MultiUsers) {
for (const auto &E : MultiUserLookup) {

auto UseI =
std::find_if(MBB->instr_begin(), MBB->instr_end(),
[&](MachineInstr &MI) -> bool { return &MI == E.first; });
[&](MachineInstr &MI) -> bool { return &MI == E.second; });

if (UseI == MBB->instr_end())
continue;

LLVM_DEBUG(
dbgs() << "Rescheduling Multi-Use Instructions Lexographically.";);
Changed |= rescheduleLexographically(
E.second, MBB, [&]() -> MachineBasicBlock::iterator { return UseI; });
MultiUsers[E.second], MBB,
[&]() -> MachineBasicBlock::iterator { return UseI; });
}

PseudoIdempotentInstCount = PseudoIdempotentInstructions.size();
Expand Down

0 comments on commit 4d89462

Please sign in to comment.