Skip to content

[AArch64][GlobalISel] Combine G_UNMERGE(G_DUPLANE16) -> G_DUPLANE16 #142731

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 1 commit into from
Jun 9, 2025
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
18 changes: 17 additions & 1 deletion llvm/lib/Target/AArch64/AArch64Combine.td
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ def form_duplane : GICombineRule <
(apply [{ applyDupLane(*${root}, MRI, B, ${matchinfo}); }])
>;

// Clean up G_UNMERGE(G_DUPLANE16) -> G_DUPLANE16
class unmerge_duplane<Instruction Op> : GICombineRule <
(defs root:$root),
(match (Op $a, $src, $c),
(G_UNMERGE_VALUES $d1, $d2, $a):$root,
[{ return MRI.getType(${d1}.getReg()).getSizeInBits() == 64; }]),
(apply (GIReplaceReg $d2, $d1), (Op $d1, $src, $c))
>;
def unmerge_duplane8 : unmerge_duplane<G_DUPLANE8>;
def unmerge_duplane16 : unmerge_duplane<G_DUPLANE16>;
def unmerge_duplane32 : unmerge_duplane<G_DUPLANE32>;
// G_DUPLANE64 is not included as the result in scalar.
def unmerge_duplanes : GICombineGroup<[unmerge_duplane8, unmerge_duplane16,
unmerge_duplane32]>;

def shuffle_vector_lowering : GICombineGroup<[dup, form_duplane, rev, ext, zip,
uzp, trn, fullrev, shuf_to_ins]>;

Expand Down Expand Up @@ -325,7 +340,8 @@ def AArch64PostLegalizerLowering
lower_vector_fcmp, form_truncstore,
vector_sext_inreg_to_shift,
unmerge_ext_to_unmerge, lower_mulv2s64,
vector_unmerge_lowering, insertelt_nonconst]> {
vector_unmerge_lowering, insertelt_nonconst,
unmerge_duplanes]> {
}

// Post-legalization combines which are primarily optimizations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple aarch64 -run-pass=aarch64-postlegalizer-lowering -verify-machineinstrs %s -o - | FileCheck %s

---
name: unmerge_dup8
legalized: true
body: |
bb.1.entry:
; CHECK-LABEL: name: unmerge_dup8
; CHECK: [[COPY:%[0-9]+]]:_(<16 x s8>) = COPY $q0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
; CHECK-NEXT: [[DUPLANE8_:%[0-9]+]]:_(<8 x s8>) = G_DUPLANE8 [[COPY]], [[C]](s64)
; CHECK-NEXT: $d0 = COPY [[DUPLANE8_]](<8 x s8>)
; CHECK-NEXT: $d1 = COPY [[DUPLANE8_]](<8 x s8>)
; CHECK-NEXT: RET_ReallyLR implicit $x0
%0:_(<16 x s8>) = COPY $q0
%1:_(s64) = G_CONSTANT i64 1
%2:_(<16 x s8>) = G_DUPLANE8 %0, %1
%3:_(<8 x s8>), %4:_(<8 x s8>) = G_UNMERGE_VALUES %2
$d0 = COPY %3
$d1 = COPY %4
RET_ReallyLR implicit $x0

...
---
name: unmerge_dup16
legalized: true
body: |
bb.1.entry:
; CHECK-LABEL: name: unmerge_dup16
; CHECK: [[COPY:%[0-9]+]]:_(<8 x s16>) = COPY $q0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
; CHECK-NEXT: [[DUPLANE16_:%[0-9]+]]:_(<4 x s16>) = G_DUPLANE16 [[COPY]], [[C]](s64)
; CHECK-NEXT: $d0 = COPY [[DUPLANE16_]](<4 x s16>)
; CHECK-NEXT: $d1 = COPY [[DUPLANE16_]](<4 x s16>)
; CHECK-NEXT: RET_ReallyLR implicit $x0
%0:_(<8 x s16>) = COPY $q0
%1:_(s64) = G_CONSTANT i64 1
%2:_(<8 x s16>) = G_DUPLANE16 %0, %1
%3:_(<4 x s16>), %4:_(<4 x s16>) = G_UNMERGE_VALUES %2
$d0 = COPY %3
$d1 = COPY %4
RET_ReallyLR implicit $x0

...
---
name: unmerge_dup32
legalized: true
body: |
bb.1.entry:
; CHECK-LABEL: name: unmerge_dup32
; CHECK: [[COPY:%[0-9]+]]:_(<4 x s32>) = COPY $q0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
; CHECK-NEXT: [[DUPLANE32_:%[0-9]+]]:_(<2 x s32>) = G_DUPLANE32 [[COPY]], [[C]](s64)
; CHECK-NEXT: $d0 = COPY [[DUPLANE32_]](<2 x s32>)
; CHECK-NEXT: $d1 = COPY [[DUPLANE32_]](<2 x s32>)
; CHECK-NEXT: RET_ReallyLR implicit $x0
%0:_(<4 x s32>) = COPY $q0
%1:_(s64) = G_CONSTANT i64 1
%2:_(<4 x s32>) = G_DUPLANE32 %0, %1
%3:_(<2 x s32>), %4:_(<2 x s32>) = G_UNMERGE_VALUES %2
$d0 = COPY %3
$d1 = COPY %4
RET_ReallyLR implicit $x0

...
---
name: unmerge_dup64
legalized: true
body: |
bb.1.entry:
; CHECK-LABEL: name: unmerge_dup64
; CHECK: [[COPY:%[0-9]+]]:_(<2 x s64>) = COPY $q0
; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
; CHECK-NEXT: [[DUPLANE64_:%[0-9]+]]:_(<2 x s64>) = G_DUPLANE64 [[COPY]], [[C]](s64)
; CHECK-NEXT: [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 0
; CHECK-NEXT: [[EVEC:%[0-9]+]]:_(s64) = G_EXTRACT_VECTOR_ELT [[DUPLANE64_]](<2 x s64>), [[C1]](s64)
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
; CHECK-NEXT: [[EVEC1:%[0-9]+]]:_(s64) = G_EXTRACT_VECTOR_ELT [[DUPLANE64_]](<2 x s64>), [[C2]](s64)
; CHECK-NEXT: $d0 = COPY [[EVEC]](s64)
; CHECK-NEXT: $d1 = COPY [[EVEC1]](s64)
; CHECK-NEXT: RET_ReallyLR implicit $x0
%0:_(<2 x s64>) = COPY $q0
%1:_(s64) = G_CONSTANT i64 1
%2:_(<2 x s64>) = G_DUPLANE64 %0, %1
%3:_(s64), %4:_(s64) = G_UNMERGE_VALUES %2
$d0 = COPY %3
$d1 = COPY %4
RET_ReallyLR implicit $x0

...
14 changes: 4 additions & 10 deletions llvm/test/CodeGen/AArch64/arm64-dup.ll
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,10 @@ define <4 x i16> @test_build_illegal(<4 x i32> %in) {
; SelectionDAGBuilder here. We then added a DUPLANE on top of that, preventing
; the formation of an indexed-by-7 MLS.
define <4 x i16> @test_high_splat(<4 x i16> %a, <4 x i16> %b, <8 x i16> %v) #0 {
; CHECK-SD-LABEL: test_high_splat:
; CHECK-SD: // %bb.0: // %entry
; CHECK-SD-NEXT: mls.4h v0, v1, v2[7]
; CHECK-SD-NEXT: ret
;
; CHECK-GI-LABEL: test_high_splat:
; CHECK-GI: // %bb.0: // %entry
; CHECK-GI-NEXT: dup.8h v2, v2[7]
; CHECK-GI-NEXT: mls.4h v0, v2, v1
; CHECK-GI-NEXT: ret
; CHECK-LABEL: test_high_splat:
; CHECK: // %bb.0: // %entry
; CHECK-NEXT: mls.4h v0, v1, v2[7]
; CHECK-NEXT: ret
entry:
%shuffle = shufflevector <8 x i16> %v, <8 x i16> undef, <4 x i32> <i32 7, i32 7, i32 7, i32 7>
%mul = mul <4 x i16> %shuffle, %b
Expand Down
Loading
Loading