[llvm] [AArch64] G_BITCAST should not change bitwidths (PR #81031)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 11:47:07 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>

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
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});
 

``````````

</details>


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


More information about the llvm-commits mailing list