Skip to content

Commit 6c15292

Browse files
committed
[LoongArch] Optimize bitcasting vector-extracted fp element to integer
1 parent 958d496 commit 6c15292

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,12 @@ foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64] in {
17931793
def : RegRegStPat<store, XVSTX, LASX256, vt>;
17941794
}
17951795

1796+
// Bitcast float/double element extracted from vector to integer.
1797+
def : Pat<(loongarch_movfr2gr_s_la64 (f32 (vector_extract v8f32:$xj, uimm3:$imm))),
1798+
(XVPICKVE2GR_W v8f32:$xj, uimm3:$imm)>;
1799+
def : Pat<(i64 (bitconvert (f64 (vector_extract v4f64:$xj, uimm2:$imm)))),
1800+
(XVPICKVE2GR_D v4f64:$xj, uimm2:$imm)>;
1801+
17961802
// Vector extraction with constant index.
17971803
def : Pat<(i64 (vector_extract v32i8:$xj, uimm4:$imm)),
17981804
(VPICKVE2GR_B (EXTRACT_SUBREG v32i8:$xj, sub_128), uimm4:$imm)>;

llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,12 @@ foreach vt = [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64] in {
19931993
def : RegRegStPat<store, VSTX, LSX128, vt>;
19941994
}
19951995

1996+
// Bitcast float/double element extracted from vector to integer.
1997+
def : Pat<(loongarch_movfr2gr_s_la64 (f32 (vector_extract v4f32:$vj, uimm2:$imm))),
1998+
(VPICKVE2GR_W v4f32:$vj, uimm2:$imm)>;
1999+
def : Pat<(i64 (bitconvert (f64 (vector_extract v2f64:$vj, uimm1:$imm)))),
2000+
(VPICKVE2GR_D v2f64:$vj, uimm1:$imm)>;
2001+
19962002
// Vector extraction with constant index.
19972003
def : Pat<(i64 (vector_extract v16i8:$vj, uimm4:$imm)),
19982004
(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/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

0 commit comments

Comments
 (0)