Skip to content

[AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, instead of checking bit width. #68189

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

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

sstipano
Copy link
Contributor

@sstipano sstipano commented Oct 4, 2023

In D151116 it was suggested to have a set of classes to cover every possible case. This does it for bitcast first.

closes #79578

@sstipano sstipano changed the title [AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, [AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, instead of checking bit width. Oct 4, 2023
@sstefan1 sstefan1 requested a review from arsenm October 4, 2023 08:28
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

typeInSet(Ty, AllPtrTypes) || Ty.isPointer();
}

static LegalityPredicate isRegType(unsigned TypeIdx,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a comment explaining what this is. In particular how is it different from isRegisterType and why do we need both (and can we have better names for them)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRegisterType check is not sufficient. For example it considers v13s32 as legal which doesn't have corresponding reg class. If this approach is accepted, this would be the first step to replace isRegisterType with isRegType (we can name it differently, of course). The idea is to replace it step by step because it is not as straight forward as replacing all calls to isRegisterType with isRegType.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good plan. Could you add a TODO comment to isRegisterType saying that all uses should be migrated to isRegType?

@jayfoad
Copy link
Contributor

jayfoad commented Oct 6, 2023

There is also some relevant discussion on https://reviews.llvm.org/D148096 which introduced isIllegalRegisterType.

Do we really need both isIllegalRegisterType and isRegType?

@sstipano
Copy link
Contributor Author

sstipano commented Oct 6, 2023

There is also some relevant discussion on https://reviews.llvm.org/D148096 which introduced isIllegalRegisterType.

Do we really need both isIllegalRegisterType and isRegType?

I think once we replace all usage of isRegisterType we could do without isIllegalRegisterType.

const LLT V2GlobalPtr = LLT::fixed_vector(2, GlobalPtr);
const LLT V4GlobalPtr = LLT::fixed_vector(4, GlobalPtr);

std::initializer_list<LLT> AllPtrTypes{V2FlatPtr, V3LocalPtr, V5LocalPtr,
Copy link
Collaborator

@petar-avramovic petar-avramovic Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jayfoad What should we do with vectors of pointers, list all possible vector sizes that fit in some register class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so. Can you write test cases for legalizing bitcast, that fail because you don't handle all pointer vector types here yet?

@sstipano
Copy link
Contributor Author

@jayfoad ping

@sstipano sstipano requested a review from jayfoad November 30, 2023 08:41
@sstipano sstipano force-pushed the bitcast_legalizer_rework branch from 0fd67a8 to f174145 Compare January 29, 2024 19:38
@sstipano sstipano changed the title [AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, instead of checking bit width. [AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, instead of checking bit width. Closes #79578 Jan 29, 2024
@sstipano sstipano changed the title [AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, instead of checking bit width. Closes #79578 [AMDGPU][GlobalIsel] Introduce isRegType to check for legal types, instead of checking bit width. Jan 29, 2024
@sstipano
Copy link
Contributor Author

@jayfoad ping

@jayfoad
Copy link
Contributor

jayfoad commented Feb 6, 2024

There is also some relevant discussion on https://reviews.llvm.org/D148096 which introduced isIllegalRegisterType.
Do we really need both isIllegalRegisterType and isRegType?

I think once we replace all usage of isRegisterType we could do without isIllegalRegisterType.

Could you add a TODO comment to isIllegalRegisterType please?

Copy link
Contributor

@jayfoad jayfoad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just taken a fresh look at this. I do have a couple of concerns:

  1. It introduces yet another list of supported register classes, which will need to be updated whenever we add a new one. But maybe that is unavoidable.
  2. It looks like isRegisterClassType will not be super fast, especially since it has to construct all the pointer types on every call.

const LLT V2GlobalPtr = LLT::fixed_vector(2, GlobalPtr);
const LLT V4GlobalPtr = LLT::fixed_vector(4, GlobalPtr);

std::initializer_list<LLT> AllPtrTypes{V2FlatPtr, V3LocalPtr, V5LocalPtr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so. Can you write test cases for legalizing bitcast, that fail because you don't handle all pointer vector types here yet?

@sstipano
Copy link
Contributor Author

sstipano commented Feb 9, 2024

  1. It looks like isRegisterClassType will not be super fast, especially since it has to construct all the pointer types on every call.
    @jayfoad initializer_list makes things tricky. I can make pointer types static to avoid having them constructed on each call. What do you think?

@sstipano sstipano force-pushed the bitcast_legalizer_rework branch 3 times, most recently from 44016ee to f2c4211 Compare February 9, 2024 21:10

// Checks whether a type is in the list of legal register types.
static bool isRegisterClassType(LLT Ty) {
if (Ty.isVector() && Ty.getElementType().isPointer())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After #81283 this could be isPointerOrPointerVector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one should go in first?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter.

@sstipano sstipano force-pushed the bitcast_legalizer_rework branch 3 times, most recently from 78c7f36 to fae364a Compare February 12, 2024 12:34

// Checks whether a type is in the list of legal register types.
static bool isRegisterClassType(LLT Ty) {
if (Ty.isVector() && Ty.getElementType().isPointer())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter.

@sstipano sstipano force-pushed the bitcast_legalizer_rework branch from fae364a to 780b970 Compare February 12, 2024 13:12
@sstipano sstipano requested a review from jayfoad February 12, 2024 13:13
Copy link
Contributor

@jayfoad jayfoad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GlobalISel: infinite loop trying to legalize G_BUILD_VECTOR
5 participants