This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix dealing with register interval endpoints in SIInsertWaitcnts.
AcceptedPublic

Authored by kosarev on Aug 4 2023, 5:48 AM.

Details

Summary

The intended convention seems to be that the intervals do not include the
value of the end point.

Diff Detail

Event Timeline

kosarev created this revision.Aug 4 2023, 5:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 5:48 AM
kosarev requested review of this revision.Aug 4 2023, 5:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2023, 5:48 AM
foad added a comment.Aug 4 2023, 6:34 AM

Nak without more explanation. What does this fix?

kosarev updated this revision to Diff 547288.Aug 4 2023, 11:28 AM

Update the commit description.

kosarev edited the summary of this revision. (Show Details)Aug 4 2023, 11:29 AM
foad added a comment.Aug 5 2023, 2:51 AM

Is this NFC? So long as the two pieces of code you updated are consistent, there is no bug, is there?

Is this NFC? So long as the two pieces of code you updated are consistent, there is no bug, is there?

What is the SGPR interval change consistent with?

For VGPRs, I guess seeing it an NFC rather than a couple bugs masking one another would imply being fine with different instances of the same type having different invariants or maybe disregarding the conceptual dimension of it all whatsoever, if this is a better crime.

foad added a comment.Aug 7 2023, 3:23 AM

NFC is not about "conceptual dimensions", it is about whether (to the best of your understanding) this patch will change the behaviour of the compiler.

Jay, do you suggest this should be marked NFC?

foad added a comment.Aug 7 2023, 5:15 AM

Jay, do you suggest this should be marked NFC?

Yes, because it looks to me like it does not change any behaviour. But I really wanted to understand whether it was *intended* to change any behaviour.

But I really wanted to understand whether it was *intended* to change any behaviour.

This fixes incorrect code and so was the intention. The original code is known to be incorrect because it violates use conventions for RegInterval as a concept, which in turn we know from its other uses, of which there are many.

In my view, being a fix, this cannot be an NFC. I also think that there is little value in defining NFC as a change that doesn't cause observable behaviour changes purely because there happened to be no uses yet that would otherwise expose the difference.

Consider this:

 int multiply(int a, int b) {
-    return a + b;
+    return a * b;
 }

 ...
 
 // Currently the only use of multiply().
 return multiply(2, 2);

I see this a functional change, and in my opinion that does not and should not depend on what other uses multiply() may have at the time of, say, submitting such a patch. That also does not and should not change anything in whether the original code should be seen correct.

This is solely to explain my views. I have no intention to insist on anything in terms of NFC marks.

foad accepted this revision.Aug 7 2023, 6:24 AM

This fixes incorrect code and so was the intention. The original code is known to be incorrect because it violates use conventions for RegInterval as a concept, which in turn we know from its other uses, of which there are many.

OK. I was mostly looking at the current upstream code, where RegisterEncoding does not use RegIntervals. Having looked more closely at what you did in D157088, I think I understand your point of view.

I would have found it less confusing if you had swapped the order of these two patches, or even squashed them together, but it does not really matter now.

This revision is now accepted and ready to land.Aug 7 2023, 6:24 AM
kosarev updated this revision to Diff 548942.Aug 10 2023, 2:41 AM

Rebased on the current top of tree. Remove dependency on D157088.

@foad Jay, does this still LGTY after the rework?

foad added a comment.Aug 14 2023, 5:38 AM

Yes it looks fine but I would not call it a "fix" since there is no bug here. (The rationale you gave before: "The original code is known to be incorrect because it violates use conventions for RegInterval as a concept, which in turn we know from its other uses, of which there are many" no longer applies, since this is no longer based on D157088.)

Yes it looks fine but I would not call it a "fix" since there is no bug here.

Right. There still seems to be a problem with testing against the SGPR range, however, with SQ_MAX_PGM_SGPRS being used as the end of the range where in fact it seems to be the size of the SGPR interval (and Encoding.SGPRL never used). Then changing it to assert(Reg >= Encoding.SGPR0 && Reg <= Encoding.SGPRL); doesn't work because getAddressableNumSGPRs() doesn't seem to include EXEC, which it seems was the expectation initially.

I'm going to update this once again to fix that, and then let's see if using RegUnits can be a better alternative to the intervals as you suggested elsewhere.