Skip to content

[AArch64] G_BITCAST should not change bitwidths #81031

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

Closed
wants to merge 1 commit into from

Conversation

AZero13
Copy link
Contributor

@AZero13 AZero13 commented Feb 7, 2024

G_BITCAST is not allowed to change the bitwidths, but it has for far too long.

There does not seem to be any tests that rely on this behavior anymore, so it seems right to make this change now.

G_BITCAST is not allowed to change the bitwidths, but it has for far too long.

There does not seem to be any tests that rely on this behavior anymore, so it seems right to make this change now.
@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2024

@llvm/pr-subscribers-backend-aarch64

Author: AtariDreams (AtariDreams)

Changes

G_BITCAST is not allowed to change the bitwidths, but it has for far too long.

There does not seem to be any tests that rely on this behavior anymore, so it seems right to make this change now.


Full diff: https://github.com/llvm/llvm-project/pull/81031.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp (+12-7)
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index cbf5655706e694..b4e6323dcf34c1 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -743,13 +743,18 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
 
   // Casts for 32 and 64-bit width type are just copies.
   // Same for 128-bit width type, except they are on the FPR bank.
-  getActionDefinitionsBuilder(G_BITCAST)
-      // FIXME: This is wrong since G_BITCAST is not allowed to change the
-      // number of bits but it's what the previous code described and fixing
-      // it breaks tests.
-      .legalForCartesianProduct({s8, s16, s32, s64, s128, v16s8, v8s8, v4s8,
-                                 v8s16, v4s16, v2s16, v4s32, v2s32, v2s64,
-                                 v2p0});
+  getActionDefinitionsBuilder(G_BITCAST).legalIf(
+      [=](const LegalityQuery &Query) {
+        const LLT &DstTy = Query.Types[0];
+        const LLT &SrcTy = Query.Types[1];
+        // Bitcast needs to stick to the same bit-width
+        if (DstTy.getSizeInBits() != SrcTy.getSizeInBits())
+          return false;
+        return llvm::is_contained({s8, s16, s32, s64, s128, v16s8, v8s8, v4s8,
+                                   v8s16, v4s16, v2s16, v4s32, v2s32, v2s64,
+                                   v2p0},
+                                  DstTy);
+      });
 
   getActionDefinitionsBuilder(G_VASTART).legalFor({p0});
 

Copy link

github-actions bot commented Feb 7, 2024

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

@davemgreen
Copy link
Collaborator

This one is being addressed in #80505

@AZero13 AZero13 closed this Feb 7, 2024
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.

3 participants