Skip to content

Commit 1ca411c

Browse files
authored
[LoongArch] Codegen for concat_vectors with LASX
Fixes: #107355 Reviewed By: SixWeining Pull Request: #107523
1 parent e64a1c0 commit 1ca411c

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ LoongArchTargetLowering::LoongArchTargetLowering(const TargetMachine &TM,
297297
setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom);
298298
setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom);
299299
setOperationAction(ISD::BUILD_VECTOR, VT, Custom);
300+
setOperationAction(ISD::CONCAT_VECTORS, VT, Legal);
300301

301302
setOperationAction(ISD::SETCC, VT, Legal);
302303
setOperationAction(ISD::VSELECT, VT, Legal);

llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,12 @@ def : Pat<(v4i32 (fp_to_uint (v4f64 LASX256:$vj))),
17891789
v4f64:$vj)),
17901790
sub_128)>;
17911791

1792+
// XVPERMI_Q
1793+
foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64] in
1794+
def : Pat<(vt (concat_vectors LSX128:$vd, LSX128:$vj)),
1795+
(XVPERMI_Q (SUBREG_TO_REG (i64 0), LSX128:$vd, sub_128),
1796+
(SUBREG_TO_REG (i64 0), LSX128:$vj, sub_128), 2)>;
1797+
17921798
} // Predicates = [HasExtLASX]
17931799

17941800
/// Intrinsic pattern
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc --mtriple=loongarch64 --mattr=+lasx < %s | FileCheck %s
3+
4+
;; Without this patch(codegen for concat_vectors), the test will hang.
5+
@g_156 = external global [12 x i32]
6+
@g_490 = external global i32
7+
@g_813 = external global i32
8+
9+
define void @foo() {
10+
; CHECK-LABEL: foo:
11+
; CHECK: # %bb.0: # %entry
12+
; CHECK-NEXT: pcalau12i $a0, %got_pc_hi20(g_156)
13+
; CHECK-NEXT: ld.d $a0, $a0, %got_pc_lo12(g_156)
14+
; CHECK-NEXT: pcalau12i $a1, %got_pc_hi20(g_490)
15+
; CHECK-NEXT: ld.d $a1, $a1, %got_pc_lo12(g_490)
16+
; CHECK-NEXT: ld.w $a2, $a0, 24
17+
; CHECK-NEXT: pcalau12i $a3, %got_pc_hi20(g_813)
18+
; CHECK-NEXT: ld.d $a3, $a3, %got_pc_lo12(g_813)
19+
; CHECK-NEXT: st.w $zero, $a1, 0
20+
; CHECK-NEXT: st.w $a2, $a3, 0
21+
; CHECK-NEXT: vrepli.b $vr0, 0
22+
; CHECK-NEXT: vst $vr0, $a0, 32
23+
; CHECK-NEXT: xvpermi.q $xr0, $xr0, 2
24+
; CHECK-NEXT: xvst $xr0, $a0, 0
25+
; CHECK-NEXT: st.w $zero, $a0, 20
26+
; CHECK-NEXT: ret
27+
entry:
28+
store i32 0, ptr getelementptr inbounds (i8, ptr @g_156, i64 20), align 4
29+
store i32 0, ptr @g_490, align 4
30+
%0 = load i32, ptr getelementptr inbounds (i8, ptr @g_156, i64 24), align 4
31+
store i32 %0, ptr @g_813, align 4
32+
tail call void @llvm.memset.p0.i64(ptr @g_156, i8 0, i64 48, i1 false)
33+
store i32 0, ptr getelementptr inbounds (i8, ptr @g_156, i64 20), align 4
34+
ret void
35+
}

0 commit comments

Comments
 (0)