Skip to content

[GlobalISel][AArch64] Legalize G_SPLAT_VECTOR #114006

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 12 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/Target/GlobalISel/SelectionDAGCompat.td
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def : GINodeEquiv<G_INSERT_VECTOR_ELT, vector_insert>;
def : GINodeEquiv<G_CONCAT_VECTORS, concat_vectors>;
def : GINodeEquiv<G_BUILD_VECTOR, build_vector>;
def : GINodeEquiv<G_EXTRACT_SUBVECTOR, extract_subvector>;
def : GINodeEquiv<G_SPLAT_VECTOR, splat_vector>;
def : GINodeEquiv<G_FCEIL, fceil>;
def : GINodeEquiv<G_FCOS, fcos>;
def : GINodeEquiv<G_FSIN, fsin>;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,10 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
.widenScalarOrEltToNextPow2(0)
.immIdx(0); // Inform verifier imm idx 0 is handled.

// TODO: {nxv16s8, s8}, {nxv8s16, s16}
getActionDefinitionsBuilder(G_SPLAT_VECTOR)
.legalFor(HasSVE, {{nxv4s32, s32}, {nxv2s64, s64}});

getLegacyLegalizerInfo().computeTables();
verify(*ST.getInstrInfo());
}
Expand Down
73 changes: 73 additions & 0 deletions llvm/test/CodeGen/AArch64/GlobalISel/select-splat-vector.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
; RUN: llc < %s -mtriple aarch64 -mattr=+sve -aarch64-enable-gisel-sve=1 | FileCheck %s --check-prefixes=CHECK,CHECK-SDAG
; RUN: llc < %s -mtriple aarch64 -mattr=+sve -global-isel -aarch64-enable-gisel-sve=1 | FileCheck %s --check-prefixes=CHECK,CHECK-GS

; REQUIRES: asserts, aarch64-registered-target

;; add
define <vscale x 2 x i64> @addnxv2i64(<vscale x 2 x i64> %a, <vscale x 2 x i64> %b) {
; CHECK-SDAG-LABEL: addnxv2i64:
; CHECK-SDAG: // %bb.0: // %entry
; CHECK-SDAG-NEXT: add z0.d, z0.d, #9 // =0x9
; CHECK-SDAG-NEXT: ret
;
; CHECK-GS-LABEL: addnxv2i64:
; CHECK-GS: // %bb.0: // %entry
; CHECK-GS-NEXT: mov w8, #9 // =0x9
; CHECK-GS-NEXT: mov z1.d, x8
; CHECK-GS-NEXT: add z0.d, z0.d, z1.d
; CHECK-GS-NEXT: ret
entry:
%c = add <vscale x 2 x i64> %a, splat (i64 9)
ret <vscale x 2 x i64> %c
}

define <vscale x 2 x i64> @splarnxv2i64(<vscale x 2 x i64> %a, <vscale x 2 x i64> %b) {
; CHECK-SDAG-LABEL: splarnxv2i64:
; CHECK-SDAG: // %bb.0: // %entry
; CHECK-SDAG-NEXT: mov z0.d, #9 // =0x9
; CHECK-SDAG-NEXT: ret
;
; CHECK-GS-LABEL: splarnxv2i64:
; CHECK-GS: // %bb.0: // %entry
; CHECK-GS-NEXT: mov w8, #9 // =0x9
; CHECK-GS-NEXT: mov z0.d, x8
; CHECK-GS-NEXT: ret
entry:
ret <vscale x 2 x i64> splat (i64 9)
}

define <vscale x 4 x i32> @addnxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
; CHECK-SDAG-LABEL: addnxv4i32:
; CHECK-SDAG: // %bb.0: // %entry
; CHECK-SDAG-NEXT: add z0.s, z0.s, #9 // =0x9
; CHECK-SDAG-NEXT: ret
;
; CHECK-GS-LABEL: addnxv4i32:
; CHECK-GS: // %bb.0: // %entry
; CHECK-GS-NEXT: mov w8, #9 // =0x9
; CHECK-GS-NEXT: mov z1.s, w8
; CHECK-GS-NEXT: add z0.s, z0.s, z1.s
; CHECK-GS-NEXT: ret
entry:
%c = add <vscale x 4 x i32> %a, splat (i32 9)
ret <vscale x 4 x i32> %c
}

define <vscale x 4 x i32> @splatnxv4i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
; CHECK-SDAG-LABEL: splatnxv4i32:
; CHECK-SDAG: // %bb.0: // %entry
; CHECK-SDAG-NEXT: mov z0.s, #9 // =0x9
; CHECK-SDAG-NEXT: ret
;
; CHECK-GS-LABEL: splatnxv4i32:
; CHECK-GS: // %bb.0: // %entry
; CHECK-GS-NEXT: mov w8, #9 // =0x9
; CHECK-GS-NEXT: mov z0.s, w8
; CHECK-GS-NEXT: ret
entry:
ret <vscale x 4 x i32> splat (i32 9)
}

;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK: {{.*}}