This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix incorrect arch assert while setting up FlatScratchInit
ClosedPublic

Authored by madhur13490 on Jul 23 2020, 2:53 AM.

Diff Detail

Event Timeline

madhur13490 created this revision.Jul 23 2020, 2:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2020, 2:53 AM

Needs test. Also not sure why we would have an assert for this here in the first place

Needs test. Also not sure why we would have an assert for this here in the first place

In fact I like the assert. It guarantees that we're not building something insane. Moreover, should we refactor this code to something more readble? :

switch(llvm::AMDGPUSubTarget) {
case GFX:8 {}
case GFX:9: {}
...
}

Only caveat is the usage of function flatScratchIsPointer(). We can get rid of its usage in its current form but in future we may want to add some code to it to take contextual decisions.

Needs test. Also not sure why we would have an assert for this here in the first place

In fact I like the assert. It guarantees that we're not building something insane. Moreover, should we refactor this code to something more readble? :

switch(llvm::AMDGPUSubTarget) {
case GFX:8 {}
case GFX:9: {}
...
}

Only caveat is the usage of function flatScratchIsPointer(). We can get rid of its usage in its current form but in future we may want to add some code to it to take contextual decisions.

I would like to purge all checks of the generation. The relevant bit is flatScratchIsPointer. The generation is redundant and potentially misleading.

Needs test. Also not sure why we would have an assert for this here in the first place

In fact I like the assert. It guarantees that we're not building something insane. Moreover, should we refactor this code to something more readble? :

switch(llvm::AMDGPUSubTarget) {
case GFX:8 {}
case GFX:9: {}
...
}

Only caveat is the usage of function flatScratchIsPointer(). We can get rid of its usage in its current form but in future we may want to add some code to it to take contextual decisions.

I would like to purge all checks of the generation. The relevant bit is flatScratchIsPointer. The generation is redundant and potentially misleading.

I am not sure what does that mean. Do you agree with my way of refactoring or you're suggesting something else? With my approach there won't be any checks as I said we can get rid of flatScratchIsPointer() too.

I am not sure what does that mean. Do you agree with my way of refactoring or you're suggesting something else? With my approach there won't be any checks as I said we can get rid of flatScratchIsPointer() too.

I mean exactly the opposite. We should not check the generation anywhere. The hardware does not make changes in a nice, disciplined, sequenced way. Everything should be based on specific feature checks. I.e. there should only be flatScratchIsPointer checks, and nothing checking getGeneration

arsenm requested changes to this revision.Jul 23 2020, 8:01 AM
This revision now requires changes to proceed.Jul 23 2020, 8:01 AM

I am not sure what does that mean. Do you agree with my way of refactoring or you're suggesting something else? With my approach there won't be any checks as I said we can get rid of flatScratchIsPointer() too.

I mean exactly the opposite. We should not check the generation anywhere. The hardware does not make changes in a nice, disciplined, sequenced way. Everything should be based on specific feature checks. I.e. there should only be flatScratchIsPointer checks, and nothing checking getGeneration

I think we have to check getGeneration at some point because meaning of FlatScratchInit is different for every arch (so the codegen). I don't think flatScratchIsPointer() is enough for that. BTW I'd like to handle refactoring in a separate patch. We should let this land with a test.

arsenm accepted this revision.Jul 23 2020, 10:05 AM

This doesn't fix an assert, it just changing it for documentation

This revision is now accepted and ready to land.Jul 23 2020, 10:05 AM

Can we just add a predicate for whatever necessitates the SETREG for gfx10+? No idea on a good name, but if it were flatScratchIsHwreg() and it implied flatScratchIsPointer() this becomes:

if (ST.flatScratchIsHwreg()) {
  // pointer add then S_SETREG
} else if (ST.flatScratchIsPointer()) (
  // pointer add
} else {
  // size and offset dance
}
llvm_unreachable();

I agree that the existing assert here doesn't really mean anything, not sure why I wrote it.

Can we just add a predicate for whatever necessitates the SETREG for gfx10+? No idea on a good name, but if it were flatScratchIsHwreg() and it implied flatScratchIsPointer() this becomes:

if (ST.flatScratchIsHwreg()) {
  // pointer add then S_SETREG
} else if (ST.flatScratchIsPointer()) (
  // pointer add
} else {
  // size and offset dance
}
llvm_unreachable();

I agree that the existing assert here doesn't really mean anything, not sure why I wrote it.

Rather, the llvm_unreachable isn't needed if we consider the offset/add case as the "default", but maybe we should predicate it too? It would be nice if we could do this all in a way that was statically known to cover all the targets we have.

Could we combine the various predicate functions into one which returns an enumeration instead? Similar to Madhur's proposal, but without the direct reference to GFX#? I.e.

switch (ST.getFlatScratchSetupKind()) {
AMDGPU::PointerInHwreg:
  // ...
  break;
AMDGPU::PointerInSGPR:
  // ...
  break;
AMDGPU::SizeAndOffsetInSGPR:
  // ...
  break;
}

Then when we add a new variant the compiler points us to everywhere that cares.

This revision was automatically updated to reflect the committed changes.

Can we just add a predicate for whatever necessitates the SETREG for gfx10+? No idea on a good name, but if it were flatScratchIsHwreg() and it implied flatScratchIsPointer() this becomes:

if (ST.flatScratchIsHwreg()) {
  // pointer add then S_SETREG
} else if (ST.flatScratchIsPointer()) (
  // pointer add
} else {
  // size and offset dance
}
llvm_unreachable();

I agree that the existing assert here doesn't really mean anything, not sure why I wrote it.

Rather, the llvm_unreachable isn't needed if we consider the offset/add case as the "default", but maybe we should predicate it too? It would be nice if we could do this all in a way that was statically known to cover all the targets we have.

Could we combine the various predicate functions into one which returns an enumeration instead? Similar to Madhur's proposal, but without the direct reference to GFX#? I.e.

switch (ST.getFlatScratchSetupKind()) {
AMDGPU::PointerInHwreg:
  // ...
  break;
AMDGPU::PointerInSGPR:
  // ...
  break;
AMDGPU::SizeAndOffsetInSGPR:
  // ...
  break;
}

Then when we add a new variant the compiler points us to everywhere that cares.

Yeah, let's handle this in a separate patch.