Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MachineLICM] Correctly Apply Register Masks #95746

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,7 @@ static bool InstructionStoresToFI(const MachineInstr *MI, int FI) {
static void applyBitsNotInRegMaskToRegUnitsMask(const TargetRegisterInfo &TRI,
BitVector &RUs,
const uint32_t *Mask) {
const unsigned NumRUs = TRI.getNumRegUnits();
BitVector RUsInMask(NumRUs);
BitVector RUsNotInMask(NumRUs);
BitVector ClobberedRUs(TRI.getNumRegUnits(), true);
const unsigned NumRegs = TRI.getNumRegs();
const unsigned MaskWords = (NumRegs + 31) / 32;
for (unsigned K = 0; K < MaskWords; ++K) {
Expand All @@ -438,21 +436,15 @@ static void applyBitsNotInRegMaskToRegUnitsMask(const TargetRegisterInfo &TRI,
if (PhysReg == NumRegs)
break;

if (!PhysReg)
continue;

// Extract the bit and apply it to the appropriate mask.
auto &Mask = ((Word >> Bit) & 1) ? RUsInMask : RUsNotInMask;
for (MCRegUnitIterator RUI(PhysReg, &TRI); RUI.isValid(); ++RUI)
Mask.set(*RUI);
// Check if we have a valid PhysReg that is set in the mask.
if (PhysReg && ((Word >> Bit) & 1)) {
Pierre-vh marked this conversation as resolved.
Show resolved Hide resolved
for (MCRegUnitIterator RUI(PhysReg, &TRI); RUI.isValid(); ++RUI)
ClobberedRUs.reset(*RUI);
}
}
}

// If a RU needs to be set because it's not in the RegMask, only set it
// if all registers from that RU are not in the mask either.
RUsNotInMask &= RUsInMask.flip();

RUs |= RUsNotInMask;
RUs |= ClobberedRUs;
}

/// Examine the instruction for potentai LICM candidate. Also
Expand Down
Loading