Memory legalizer, waitcnt, and shrink passes can perturb the instructions, which means that the post-RA hazard recognizer pass should run after them. Otherwise, one of those passes may invalidate the work done by the hazard recognizer. Note that this has adverse side-effect that any consecutive S_NOP 0's, emitted by the hazard recognizer, will not be shrunk into a single S_NOP <N>. This should be addressed in a follow-on patch.
Details
Diff Detail
Event Timeline
lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | ||
---|---|---|
905–906 | I'm surprised we run shrink after this point. I think this can plausibly be an issue. The immediate materialize would eliminate a wait state that wasn't necessary, but now is since the copy is eliminated. I think in practice the shrink pass isn't very good at folding immediates post-RA, if it even tries |
lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | ||
---|---|---|
905–906 | I will move the hazard recognizer after shrink instructions, unless you're suggesting that the shrink pass be moved somewhere else? I think that moving the hazard recognizer after the shrink pass has the side-effect that some S_NOP 0's won't be collapsed into, say S_NOP <N>. The hazard recognizer just creates individual S_NOP 0 instrs and is relying on the shrink pass to turn them into S_NOP <N>. I suppose the hazard recognizer could be enhanced to generate the S_NOP <N> instrs on its own. |
lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | ||
---|---|---|
905–906 | Yes, the hazard recognizer ideally would do that. The shrink pass deals with this as a workaround for it seeming to assume all nops are the same. It's probably OK to leave as-is for now |
lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | ||
---|---|---|
905–906 | I would move shrink before hazard recognizer. |
I'm surprised we run shrink after this point.
I think this can plausibly be an issue.
Suppose you had something like
%vgpr0 = V_FOO
<some hazard>
%vgpr1 = V_MOV_B32 5
%vgpr2 = V_BAR %vgpr1
The immediate materialize would eliminate a wait state that wasn't necessary, but now is since the copy is eliminated. I think in practice the shrink pass isn't very good at folding immediates post-RA, if it even tries