[WaveTransform] Redesign lane mask contribution mechanism to propagate known subsets of exec - #3804
[WaveTransform] Redesign lane mask contribution mechanism to propagate known subsets of exec#3804lalaniket8 wants to merge 5 commits into
Conversation
|
PSDB Build Link: http://mlse-bdc-20dd129:8065/#/builders/10/builds/752 |
| // Do not optimize over branches | ||
| if (PrevWait && (MI.isCall() || MI.isReturn() || MI.isBranch())) { | ||
| PrevWait->moveBefore(&MI); | ||
| // Anchor before leading terminator pseudos (e.g. SI_WAVE_CF_EDGE). |
There was a problem hiding this comment.
I posted PR #3813. Revert these changes later after it gets merged.
|
PSDB Build Link: http://mlse-bdc-20dd129:8065/#/builders/10/builds/755 |
53b0f3d to
040d0e6
Compare
|
PSDB Build Link: http://mlse-bdc-20dd129:8065/#/builders/10/builds/760 |
| Zero, ///< 0 (Reg & EXEC == 0). | ||
| Subset, ///< Subset of EXEC (Reg & EXEC == Reg). | ||
| Exec, ///< EXEC or -1 (Reg & EXEC == EXEC). | ||
| NeedsMask, ///< Superset/unknown; emit Reg & EXEC. |
There was a problem hiding this comment.
NeedsMask doesn't fit well as a Kind. It could be a None or Unknown for none-of-the-other known kinds. It should go as the first entry and push Zero down.
There was a problem hiding this comment.
NeedsMaks cannot be used as else because it represents 2 classes : Superset of exec and cases where no property is known about the register, in which case we conservatively chose to mask it.
There was a problem hiding this comment.
Whether it's a superset or an unknown value, you eventually need a new Kind. NeedsMask doesn't accurately describe this category.
In situations like this, when it's difficult to come up with a concise and meaningful name, None or Unknown are commonly used. They represent the default state for values that don't naturally fit into any of the other defined MaskKinds.
| Subset, ///< Subset of EXEC (Reg & EXEC == Reg). | ||
| Exec, ///< EXEC or -1 (Reg & EXEC == EXEC). |
There was a problem hiding this comment.
Related question here;
Why do you have to add a single kind for both EXEC and AllOnes scenarios?
Don't we need a separate AllOnes kind just like Zero?
There was a problem hiding this comment.
That's a good question and relates to what earlier happened to the contributed AllOnes in the buildMergeLaneMasks section:
It has a bunch of ifs and elses that decide which lane mask instr is built - if it sees 'AllOnes' contributed, it replaces it with exec.
There is a single point in rewrite step2.1 where AllOnes is contributed. So we can safely contribute exec directly.
There was a problem hiding this comment.
If AllOnes is replaced here, let's avoid mentioning -1 in the comment. There's no need to leave traces of intermediate designs as we are nearing the upstream effort.
| } | ||
|
|
||
| /// Classify \p Reg by its relationship to EXEC; the all-ones constant (-1) | ||
| /// maps to \ref LaneMaskKind::Exec since -1 & EXEC == EXEC. |
There was a problem hiding this comment.
I am trying to understand what scenario this -1 & EXEC == EXEC is?
Don't we have other combinations with -1?
Replace the analysis-driven, all-ones–materializing lane-mask merge with an explicit
LaneMaskKindclassification supplied by the caller during rewrite step. Callers now describe how each contribution relates toEXEC;buildMergeLaneMasksswitches on that kind to pick the cheapest merge.LaneMaskKind(new)Enum classifying a lane mask vs.
EXEC:Zero—Reg & EXEC == 0Subset—Reg & EXEC == RegExec—EXECor-1(Reg & EXEC == EXEC)NeedsMask— superset/unknown; emitReg & EXECclassifyLaneMask()derives it (EXEC →Exec, const ±1/0, subset viaLMA, elseNeedsMask).buildMergeLaneMasksLaneMaskKind CurKindinstead ofAMDGPULaneMaskAnalysis *LMA; branch selection is now aswitch.ZeroemitsMOV 0; accumulator +Zeroelides the merge (copy only whenDst != Prev).AMDGPULaneMaskUpdateraddAvailable()gains aLaneMaskKind Kindargument.LMAmember andsetLaneMaskAnalysis().AMDGPUWaveTransformRegAllOnes(-1) materialization and its dead-reg cleanup; EXEC/all-lanes contributions useLMC.ExecRegdirectly withLaneMaskKind::Exec.addAvailable()call passes an explicit kind (Exec/Zero/Subset).assert(!LaneOrigin.CondIsUndef).AMDGPUWaitSGPRHazards(fix)When sinking a wait before a terminator, anchor it before the first terminator (e.g. leading
SI_WAVE_CF_EDGE) instead of before the branch, so it is not placed between terminator pseudos.Effect
S_MOV_B64 -1emitted for all-lanes contributions.EXECvalues.