-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[LLVM][CodeGen] Fix register lane liveness tracking in RegisterPressure #88892
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
[LLVM][CodeGen] Fix register lane liveness tracking in RegisterPressure #88892
Conversation
Re-enable an old assertion in `decreaseSetPressure`.
@llvm/pr-subscribers-llvm-regalloc Author: Krzysztof Parzyszek (kparzysz) ChangesRe-enable an old assertion in Full diff: https://github.com/llvm/llvm-project/pull/88892.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/RegisterPressure.cpp b/llvm/lib/CodeGen/RegisterPressure.cpp
index f86aa3a167202f..1b89cd57b9f2c3 100644
--- a/llvm/lib/CodeGen/RegisterPressure.cpp
+++ b/llvm/lib/CodeGen/RegisterPressure.cpp
@@ -64,7 +64,7 @@ static void increaseSetPressure(std::vector<unsigned> &CurrSetPressure,
static void decreaseSetPressure(std::vector<unsigned> &CurrSetPressure,
const MachineRegisterInfo &MRI, Register Reg,
LaneBitmask PrevMask, LaneBitmask NewMask) {
- //assert((NewMask & !PrevMask) == 0 && "Must not add bits");
+ assert((NewMask & ~PrevMask).none() && "Must not add bits");
if (NewMask.any() || PrevMask.none())
return;
@@ -617,17 +617,11 @@ void RegisterOperands::adjustLaneLiveness(const LiveIntervals &LIS,
++I;
}
}
- for (auto *I = Uses.begin(); I != Uses.end();) {
- LaneBitmask LiveBefore = getLiveLanesAt(LIS, MRI, true, I->RegUnit,
- Pos.getBaseIndex());
- LaneBitmask LaneMask = I->LaneMask & LiveBefore;
- if (LaneMask.none()) {
- I = Uses.erase(I);
- } else {
- I->LaneMask = LaneMask;
- ++I;
- }
- }
+
+ // For uses just copy the copy the information from LIS.
+ for (auto &[RegUnit, LaneMask] : Uses)
+ LaneMask = getLiveLanesAt(LIS, MRI, true, RegUnit, Pos.getBaseIndex());
+
if (AddFlagsMI != nullptr) {
for (const RegisterMaskPair &P : DeadDefs) {
Register RegUnit = P.RegUnit;
@@ -1060,18 +1054,27 @@ void RegPressureTracker::bumpUpwardPressure(const MachineInstr *MI) {
// Kill liveness at live defs.
for (const RegisterMaskPair &P : RegOpers.Defs) {
Register Reg = P.RegUnit;
- LaneBitmask LiveLanes = LiveRegs.contains(Reg);
+ LaneBitmask LiveAfter = LiveRegs.contains(Reg);
LaneBitmask UseLanes = getRegLanes(RegOpers.Uses, Reg);
LaneBitmask DefLanes = P.LaneMask;
- LaneBitmask LiveAfter = (LiveLanes & ~DefLanes) | UseLanes;
- decreaseRegPressure(Reg, LiveLanes, LiveAfter);
+ LaneBitmask LiveBefore = (LiveAfter & ~DefLanes) | UseLanes;
+
+ // There may be parts of the register that were dead before the
+ // instruction, but became live afterwards. Similarly, some parts
+ // may have been killed in this instruction.
+ decreaseRegPressure(Reg, LiveAfter, LiveAfter & LiveBefore);
+ increaseRegPressure(Reg, LiveAfter, ~LiveAfter & LiveBefore);
}
// Generate liveness for uses.
for (const RegisterMaskPair &P : RegOpers.Uses) {
Register Reg = P.RegUnit;
- LaneBitmask LiveLanes = LiveRegs.contains(Reg);
- LaneBitmask LiveAfter = LiveLanes | P.LaneMask;
- increaseRegPressure(Reg, LiveLanes, LiveAfter);
+ // If this register was also in a def operand, we've handled it
+ // with defs.
+ if (getRegLanes(RegOpers.Defs, Reg).any())
+ continue;
+ LaneBitmask LiveAfter = LiveRegs.contains(Reg);
+ LaneBitmask LiveBefore = LiveAfter | P.LaneMask;
+ increaseRegPressure(Reg, LiveAfter, LiveBefore);
}
}
|
This is an alternative to #87405, since I wanted to focus on the issues causing the assertion to fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other patch doesn't really work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Just double checking, this commit is already exercised by existing tests, right?
Otherwise, could you add a test?
Yes. This assertion, when enabled without this fix, causes lots of existing AMDGPU tests to fail. |
Re-enable an old assertion in
decreaseSetPressure
.