Skip to content

Commit e740827

Browse files
authored
[LoongArch] Optimize inserting bitcasted integer element or bitcasting extracted fp element (#147043)
1 parent b7c14b6 commit e740827

File tree

7 files changed

+23
-17
lines changed

7 files changed

+23
-17
lines changed

llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file describes the baisc single-precision floating-point instructions.
9+
// This file describes the basic single-precision floating-point instructions.
1010
//
1111
//===----------------------------------------------------------------------===//
1212

llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,10 @@ def : Pat<(vector_insert v8i32:$xd, GRLenVT:$rj, uimm3:$imm),
16511651
(XVINSGR2VR_W v8i32:$xd, GRLenVT:$rj, uimm3:$imm)>;
16521652
def : Pat<(vector_insert v4i64:$xd, GRLenVT:$rj, uimm2:$imm),
16531653
(XVINSGR2VR_D v4i64:$xd, GRLenVT:$rj, uimm2:$imm)>;
1654+
def : Pat<(vector_insert v8f32:$vd, (loongarch_movgr2fr_w_la64 GPR:$rj), uimm3:$imm),
1655+
(XVINSGR2VR_W $vd, $rj, uimm3:$imm)>;
1656+
def : Pat<(vector_insert v4f64:$vd, (f64 (bitconvert i64:$rj)), uimm2:$imm),
1657+
(XVINSGR2VR_D $vd, $rj, uimm2:$imm)>;
16541658
def : Pat<(vector_insert v8f32:$xd, (f32 (vector_extract v8f32:$xj, uimm3:$imm1)), uimm3:$imm2),
16551659
(XVINSGR2VR_W $xd, (XVPICKVE2GR_W v8f32:$xj, uimm3:$imm1), uimm3:$imm2)>;
16561660
def : Pat<(vector_insert v4f64:$xd, (f64 (vector_extract v4f64:$xj, uimm2:$imm1)), uimm2:$imm2),
@@ -1851,6 +1855,12 @@ foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64] in {
18511855
def : RegRegStPat<store, XVSTX, LASX256, vt>;
18521856
}
18531857

1858+
// Bitcast float/double element extracted from vector to integer.
1859+
def : Pat<(loongarch_movfr2gr_s_la64 (f32 (vector_extract v8f32:$xj, uimm3:$imm))),
1860+
(XVPICKVE2GR_W v8f32:$xj, uimm3:$imm)>;
1861+
def : Pat<(i64 (bitconvert (f64 (vector_extract v4f64:$xj, uimm2:$imm)))),
1862+
(XVPICKVE2GR_D v4f64:$xj, uimm2:$imm)>;
1863+
18541864
// Vector extraction with constant index.
18551865
foreach imm = 16...31 in {
18561866
defvar Imm = !and(imm, 15);

llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,10 @@ def : Pat<(vector_insert v4i32:$vd, GRLenVT:$rj, uimm2:$imm),
18381838
(VINSGR2VR_W v4i32:$vd, GRLenVT:$rj, uimm2:$imm)>;
18391839
def : Pat<(vector_insert v2i64:$vd, GRLenVT:$rj, uimm1:$imm),
18401840
(VINSGR2VR_D v2i64:$vd, GRLenVT:$rj, uimm1:$imm)>;
1841+
def : Pat<(vector_insert v4f32:$vd, (loongarch_movgr2fr_w_la64 GPR:$rj), uimm2:$imm),
1842+
(VINSGR2VR_W $vd, $rj, uimm2:$imm)>;
1843+
def : Pat<(vector_insert v2f64:$vd, (f64 (bitconvert i64:$rj)), uimm1:$imm),
1844+
(VINSGR2VR_D $vd, $rj, uimm1:$imm)>;
18411845
def : Pat<(vector_insert v4f32:$vd, FPR32:$fj, uimm2:$imm),
18421846
(VINSGR2VR_W $vd, (COPY_TO_REGCLASS FPR32:$fj, GPR), uimm2:$imm)>;
18431847
def : Pat<(vector_insert v2f64:$vd, FPR64:$fj, uimm1:$imm),
@@ -2036,6 +2040,12 @@ foreach vt = [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64] in {
20362040
def : RegRegStPat<store, VSTX, LSX128, vt>;
20372041
}
20382042

2043+
// Bitcast float/double element extracted from vector to integer.
2044+
def : Pat<(loongarch_movfr2gr_s_la64 (f32 (vector_extract v4f32:$vj, uimm2:$imm))),
2045+
(VPICKVE2GR_W v4f32:$vj, uimm2:$imm)>;
2046+
def : Pat<(i64 (bitconvert (f64 (vector_extract v2f64:$vj, uimm1:$imm)))),
2047+
(VPICKVE2GR_D v2f64:$vj, uimm1:$imm)>;
2048+
20392049
// Vector extraction with constant index.
20402050
def : Pat<(i64 (vector_extract v16i8:$vj, uimm4:$imm)),
20412051
(VPICKVE2GR_B v16i8:$vj, uimm4:$imm)>;

llvm/test/CodeGen/LoongArch/lasx/ir-instruction/bitcast-extract-element.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ define i32 @bitcast_extract_v8f32(<8 x float> %a) nounwind {
55
; CHECK-LABEL: bitcast_extract_v8f32:
66
; CHECK: # %bb.0: # %entry
77
; CHECK-NEXT: xvpickve2gr.w $a0, $xr0, 7
8-
; CHECK-NEXT: movgr2fr.w $fa0, $a0
9-
; CHECK-NEXT: movfr2gr.s $a0, $fa0
108
; CHECK-NEXT: ret
119
entry:
1210
%b = extractelement <8 x float> %a, i32 7
@@ -18,8 +16,6 @@ define i64 @bitcast_extract_v4f64(<4 x double> %a) nounwind {
1816
; CHECK-LABEL: bitcast_extract_v4f64:
1917
; CHECK: # %bb.0: # %entry
2018
; CHECK-NEXT: xvpickve2gr.d $a0, $xr0, 3
21-
; CHECK-NEXT: movgr2fr.d $fa0, $a0
22-
; CHECK-NEXT: movfr2gr.d $a0, $fa0
2319
; CHECK-NEXT: ret
2420
entry:
2521
%b = extractelement <4 x double> %a, i32 3

llvm/test/CodeGen/LoongArch/lasx/ir-instruction/insert-bitcast-element.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
define <8 x float> @insert_bitcast_v8f32(<8 x float> %a, i32 %b) nounwind {
55
; CHECK-LABEL: insert_bitcast_v8f32:
66
; CHECK: # %bb.0: # %entry
7-
; CHECK-NEXT: movgr2fr.w $fa1, $a0
8-
; CHECK-NEXT: movfr2gr.s $a0, $fa1
97
; CHECK-NEXT: xvinsgr2vr.w $xr0, $a0, 1
108
; CHECK-NEXT: ret
119
entry:
@@ -17,8 +15,6 @@ entry:
1715
define <4 x double> @insert_bitcast_v4f64(<4 x double> %a, i64 %b) nounwind {
1816
; CHECK-LABEL: insert_bitcast_v4f64:
1917
; CHECK: # %bb.0: # %entry
20-
; CHECK-NEXT: movgr2fr.d $fa1, $a0
21-
; CHECK-NEXT: movfr2gr.d $a0, $fa1
2218
; CHECK-NEXT: xvinsgr2vr.d $xr0, $a0, 1
2319
; CHECK-NEXT: ret
2420
entry:

llvm/test/CodeGen/LoongArch/lsx/ir-instruction/bitcast-extract-element.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
define i32 @bitcast_extract_v4f32(<4 x float> %a) nounwind {
55
; CHECK-LABEL: bitcast_extract_v4f32:
66
; CHECK: # %bb.0: # %entry
7-
; CHECK-NEXT: vreplvei.w $vr0, $vr0, 3
8-
; CHECK-NEXT: movfr2gr.s $a0, $fa0
7+
; CHECK-NEXT: vpickve2gr.w $a0, $vr0, 3
98
; CHECK-NEXT: ret
109
entry:
1110
%b = extractelement <4 x float> %a, i32 3
@@ -16,8 +15,7 @@ entry:
1615
define i64 @bitcast_extract_v2f64(<2 x double> %a) nounwind {
1716
; CHECK-LABEL: bitcast_extract_v2f64:
1817
; CHECK: # %bb.0: # %entry
19-
; CHECK-NEXT: vreplvei.d $vr0, $vr0, 1
20-
; CHECK-NEXT: movfr2gr.d $a0, $fa0
18+
; CHECK-NEXT: vpickve2gr.d $a0, $vr0, 1
2119
; CHECK-NEXT: ret
2220
entry:
2321
%b = extractelement <2 x double> %a, i32 1

llvm/test/CodeGen/LoongArch/lsx/ir-instruction/insert-bitcast-element.ll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
define <4 x float> @insert_bitcast_v4f32(<4 x float> %a, i32 %b) nounwind {
55
; CHECK-LABEL: insert_bitcast_v4f32:
66
; CHECK: # %bb.0: # %entry
7-
; CHECK-NEXT: movgr2fr.w $fa1, $a0
8-
; CHECK-NEXT: movfr2gr.s $a0, $fa1
97
; CHECK-NEXT: vinsgr2vr.w $vr0, $a0, 1
108
; CHECK-NEXT: ret
119
entry:
@@ -17,8 +15,6 @@ entry:
1715
define <2 x double> @insert_bitcast_v2f64(<2 x double> %a, i64 %b) nounwind {
1816
; CHECK-LABEL: insert_bitcast_v2f64:
1917
; CHECK: # %bb.0: # %entry
20-
; CHECK-NEXT: movgr2fr.d $fa1, $a0
21-
; CHECK-NEXT: movfr2gr.d $a0, $fa1
2218
; CHECK-NEXT: vinsgr2vr.d $vr0, $a0, 1
2319
; CHECK-NEXT: ret
2420
entry:

0 commit comments

Comments
 (0)