Skip to content
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

[GIsel][AArch64] Legalize <2 x i16> for G_INSERT_VECTOR_ELT #65830

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

vfdff
Copy link
Contributor

@vfdff vfdff commented Sep 9, 2023

Widen the vector elements to 64 bits to make sure it legal instead by
clamping the number of elements. Depend on D153394.

Fixes #63826

@tschuett
Copy link
Member

tschuett commented Sep 9, 2023

Do we need to add widenVectorEltsToVectorMinSize to more vector operations?

@vfdff
Copy link
Contributor Author

vfdff commented Sep 9, 2023

Do we need to add widenVectorEltsToVectorMinSize to more vector operations?

Now only do the minimal fix type v2s16.

@aemerson
Copy link
Contributor

Do we need to add widenVectorEltsToVectorMinSize to more vector operations?

Now only do the minimal fix type v2s16.

And why not do widenVectorEltsToVectorMinSize()?

@vfdff
Copy link
Contributor Author

vfdff commented Sep 11, 2023

Do we need to add widenVectorEltsToVectorMinSize to more vector operations?

Now only do the minimal fix type v2s16.

And why not do widenVectorEltsToVectorMinSize()?

Thanks @aemerson. Apply your comment, refactor the widenVectorEltsToVectorMinSize to support the scalar type of Query.Types[1], then pass 1 as the type index to avoid add handling for the destination type in LegalizerHelper.

@aemerson
Copy link
Contributor

Do we need to add widenVectorEltsToVectorMinSize to more vector operations?

Now only do the minimal fix type v2s16.

And why not do widenVectorEltsToVectorMinSize()?

Thanks @aemerson. Apply your comment, refactor the widenVectorEltsToVectorMinSize to support the scalar type of Query.Types[1], then pass 1 as the type index to avoid add handling for the destination type in LegalizerHelper.

Sorry, I hadn't understood your earlier comment about the operand indexes not including the destination. Your earlier change with the LegalizerHelper addition makes sense in that context.

If you bring back that LegalizerHelper change, it seems you don't need the additional parameter to widenVectorEltsToVectorMinSize(). That is, the following patch seems to work on the <2 x s16> test case:

diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index cfb95955d1f8..cfef1cc9c299 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -2496,6 +2496,16 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
     return Legalized;
   }
   case TargetOpcode::G_INSERT_VECTOR_ELT: {
+    if (TypeIdx == 0) {
+      Observer.changingInstr(MI);
+      const LLT WideEltTy = WideTy.getElementType();
+
+      widenScalarSrc(MI, WideTy, 1, TargetOpcode::G_ANYEXT);
+      widenScalarSrc(MI, WideEltTy, 2, TargetOpcode::G_ANYEXT);
+      widenScalarDst(MI, WideTy, 0);
+      Observer.changedInstr(MI);
+      return Legalized;
+    }
     if (TypeIdx == 1) {
       Observer.changingInstr(MI);

diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index e2df8fb1321d..41433650f7c1 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -732,8 +732,7 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)

   getActionDefinitionsBuilder(G_INSERT_VECTOR_ELT)
       .legalIf(typeInSet(0, {v16s8, v8s8, v8s16, v4s16, v4s32, v2s32, v2s64}))
-      .clampMinNumElements(0, s16, 4)
-      .clampMaxNumElements(0, s16, 8);
+      .widenVectorEltsToVectorMinSize(0, 64);

   getActionDefinitionsBuilder(G_BUILD_VECTOR)
       .legalFor({{v8s8, s8},

What do you think?

Widen the vector elements to 64 bits to make sure it legal instead by
clamping the number of elements. refer to commit ccffc27.

Fixes llvm#63826
@vfdff
Copy link
Contributor Author

vfdff commented Sep 12, 2023

I roll back to avoid additional parameter to widenVectorEltsToVectorMinSize(), thanks very much for detail suggestion.

Copy link
Contributor

@aemerson aemerson left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.

@vfdff vfdff merged commit eaf23b2 into llvm:main Sep 12, 2023
2 checks passed
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
Widen the vector elements to 64 bits to make sure it legal instead by
clamping the number of elements. Depend on D153394.

Fixes llvm#63826
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.

[GISel] unable to legalize instruction: %4:_(<2 x s16>) = G_INSERT_VECTOR_ELT
3 participants