[llvm] [AArc64][SDAG] Legalise BSWAP for Neon types. (PR #179702)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 4 08:09:35 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ricardo Jesus (rj-jesus)
<details>
<summary>Changes</summary>
GlobalISel legalised BSWAP for Neon types in #<!-- -->80036.
Legalising the types keeps them from being expanded to vector_shuffle before being matched to REVs, and allows half-rotations on i16 vectors to be combined to bswap (see https://github.com/llvm/llvm-project/pull/178706#discussion_r2742804463).
---
Full diff: https://github.com/llvm/llvm-project/pull/179702.diff
2 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+5-1)
- (modified) llvm/test/Analysis/CostModel/AArch64/bswap.ll (+1-1)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 6c0544005e1dd..78c4c77b99b6f 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -1408,7 +1408,11 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
setOperationAction(ISD::SMUL_LOHI, VT, Expand);
setOperationAction(ISD::UMUL_LOHI, VT, Expand);
- setOperationAction(ISD::BSWAP, VT, Expand);
+ if (VT == MVT::v4i16 || VT == MVT::v8i16 || VT == MVT::v2i32 ||
+ VT == MVT::v4i32 || VT == MVT::v2i64)
+ setOperationAction(ISD::BSWAP, VT, Legal);
+ else
+ setOperationAction(ISD::BSWAP, VT, Expand);
setOperationAction(ISD::CTTZ, VT, Expand);
for (MVT InnerVT : MVT::fixedlen_vector_valuetypes()) {
diff --git a/llvm/test/Analysis/CostModel/AArch64/bswap.ll b/llvm/test/Analysis/CostModel/AArch64/bswap.ll
index 2df508ebe40bc..43b1d252d04ee 100644
--- a/llvm/test/Analysis/CostModel/AArch64/bswap.ll
+++ b/llvm/test/Analysis/CostModel/AArch64/bswap.ll
@@ -44,7 +44,7 @@ define void @neon() {
; CHECK-NEXT: Cost Model: Found costs of 1 for: %v2i64 = call <2 x i64> @llvm.bswap.v2i64(<2 x i64> undef)
; CHECK-NEXT: Cost Model: Found costs of 2 for: %v4i64 = call <4 x i64> @llvm.bswap.v4i64(<4 x i64> undef)
; CHECK-NEXT: Cost Model: Found costs of 1 for: %v3i32 = call <3 x i32> @llvm.bswap.v3i32(<3 x i32> undef)
-; CHECK-NEXT: Cost Model: Found costs of RThru:12 CodeSize:8 Lat:12 SizeLat:12 for: %v4i48 = call <4 x i48> @llvm.bswap.v4i48(<4 x i48> undef)
+; CHECK-NEXT: Cost Model: Found costs of 4 for: %v4i48 = call <4 x i48> @llvm.bswap.v4i48(<4 x i48> undef)
; CHECK-NEXT: Cost Model: Found costs of RThru:0 CodeSize:1 Lat:1 SizeLat:1 for: ret void
;
%v4i16 = call <4 x i16> @llvm.bswap.v4i16(<4 x i16> undef)
``````````
</details>
https://github.com/llvm/llvm-project/pull/179702
More information about the llvm-commits
mailing list