diff options
author | ZhaoQi <zhaoqi01@loongson.cn> | 2025-07-17 19:21:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-17 19:21:24 +0800 |
commit | e74082703e224740e6281fb04f9a177c42c6467f (patch) | |
tree | a6bdf378a6f0e8c1578347fe2075f4c32b7c26aa | |
parent | b7c14b6ded300b9190fe0b65881d04c54b2a9fbd (diff) | |
download | llvm-e74082703e224740e6281fb04f9a177c42c6467f.zip llvm-e74082703e224740e6281fb04f9a177c42c6467f.tar.gz llvm-e74082703e224740e6281fb04f9a177c42c6467f.tar.bz2 |
[LoongArch] Optimize inserting bitcasted integer element or bitcasting extracted fp element (#147043)
7 files changed, 23 insertions, 17 deletions
diff --git a/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td index d5a5f17..36c3011 100644 --- a/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchFloat32InstrInfo.td @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// // -// This file describes the baisc single-precision floating-point instructions. +// This file describes the basic single-precision floating-point instructions. // //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td index 6a8c9fa..a0107e4 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td @@ -1651,6 +1651,10 @@ def : Pat<(vector_insert v8i32:$xd, GRLenVT:$rj, uimm3:$imm), (XVINSGR2VR_W v8i32:$xd, GRLenVT:$rj, uimm3:$imm)>; def : Pat<(vector_insert v4i64:$xd, GRLenVT:$rj, uimm2:$imm), (XVINSGR2VR_D v4i64:$xd, GRLenVT:$rj, uimm2:$imm)>; +def : Pat<(vector_insert v8f32:$vd, (loongarch_movgr2fr_w_la64 GPR:$rj), uimm3:$imm), + (XVINSGR2VR_W $vd, $rj, uimm3:$imm)>; +def : Pat<(vector_insert v4f64:$vd, (f64 (bitconvert i64:$rj)), uimm2:$imm), + (XVINSGR2VR_D $vd, $rj, uimm2:$imm)>; def : Pat<(vector_insert v8f32:$xd, (f32 (vector_extract v8f32:$xj, uimm3:$imm1)), uimm3:$imm2), (XVINSGR2VR_W $xd, (XVPICKVE2GR_W v8f32:$xj, uimm3:$imm1), uimm3:$imm2)>; 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 { def : RegRegStPat<store, XVSTX, LASX256, vt>; } +// Bitcast float/double element extracted from vector to integer. +def : Pat<(loongarch_movfr2gr_s_la64 (f32 (vector_extract v8f32:$xj, uimm3:$imm))), + (XVPICKVE2GR_W v8f32:$xj, uimm3:$imm)>; +def : Pat<(i64 (bitconvert (f64 (vector_extract v4f64:$xj, uimm2:$imm)))), + (XVPICKVE2GR_D v4f64:$xj, uimm2:$imm)>; + // Vector extraction with constant index. foreach imm = 16...31 in { defvar Imm = !and(imm, 15); diff --git a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td index 9dd6006..962e7c2 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td @@ -1838,6 +1838,10 @@ def : Pat<(vector_insert v4i32:$vd, GRLenVT:$rj, uimm2:$imm), (VINSGR2VR_W v4i32:$vd, GRLenVT:$rj, uimm2:$imm)>; def : Pat<(vector_insert v2i64:$vd, GRLenVT:$rj, uimm1:$imm), (VINSGR2VR_D v2i64:$vd, GRLenVT:$rj, uimm1:$imm)>; +def : Pat<(vector_insert v4f32:$vd, (loongarch_movgr2fr_w_la64 GPR:$rj), uimm2:$imm), + (VINSGR2VR_W $vd, $rj, uimm2:$imm)>; +def : Pat<(vector_insert v2f64:$vd, (f64 (bitconvert i64:$rj)), uimm1:$imm), + (VINSGR2VR_D $vd, $rj, uimm1:$imm)>; def : Pat<(vector_insert v4f32:$vd, FPR32:$fj, uimm2:$imm), (VINSGR2VR_W $vd, (COPY_TO_REGCLASS FPR32:$fj, GPR), uimm2:$imm)>; def : Pat<(vector_insert v2f64:$vd, FPR64:$fj, uimm1:$imm), @@ -2036,6 +2040,12 @@ foreach vt = [v16i8, v8i16, v4i32, v2i64, v4f32, v2f64] in { def : RegRegStPat<store, VSTX, LSX128, vt>; } +// Bitcast float/double element extracted from vector to integer. +def : Pat<(loongarch_movfr2gr_s_la64 (f32 (vector_extract v4f32:$vj, uimm2:$imm))), + (VPICKVE2GR_W v4f32:$vj, uimm2:$imm)>; +def : Pat<(i64 (bitconvert (f64 (vector_extract v2f64:$vj, uimm1:$imm)))), + (VPICKVE2GR_D v2f64:$vj, uimm1:$imm)>; + // Vector extraction with constant index. def : Pat<(i64 (vector_extract v16i8:$vj, uimm4:$imm)), (VPICKVE2GR_B v16i8:$vj, uimm4:$imm)>; diff --git a/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/bitcast-extract-element.ll b/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/bitcast-extract-element.ll index 86808c7..09ce1a0 100644 --- a/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/bitcast-extract-element.ll +++ b/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/bitcast-extract-element.ll @@ -5,8 +5,6 @@ define i32 @bitcast_extract_v8f32(<8 x float> %a) nounwind { ; CHECK-LABEL: bitcast_extract_v8f32: ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: xvpickve2gr.w $a0, $xr0, 7 -; CHECK-NEXT: movgr2fr.w $fa0, $a0 -; CHECK-NEXT: movfr2gr.s $a0, $fa0 ; CHECK-NEXT: ret entry: %b = extractelement <8 x float> %a, i32 7 @@ -18,8 +16,6 @@ define i64 @bitcast_extract_v4f64(<4 x double> %a) nounwind { ; CHECK-LABEL: bitcast_extract_v4f64: ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: xvpickve2gr.d $a0, $xr0, 3 -; CHECK-NEXT: movgr2fr.d $fa0, $a0 -; CHECK-NEXT: movfr2gr.d $a0, $fa0 ; CHECK-NEXT: ret entry: %b = extractelement <4 x double> %a, i32 3 diff --git a/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/insert-bitcast-element.ll b/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/insert-bitcast-element.ll index 7b2461b..b37b525 100644 --- a/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/insert-bitcast-element.ll +++ b/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/insert-bitcast-element.ll @@ -4,8 +4,6 @@ define <8 x float> @insert_bitcast_v8f32(<8 x float> %a, i32 %b) nounwind { ; CHECK-LABEL: insert_bitcast_v8f32: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: movgr2fr.w $fa1, $a0 -; CHECK-NEXT: movfr2gr.s $a0, $fa1 ; CHECK-NEXT: xvinsgr2vr.w $xr0, $a0, 1 ; CHECK-NEXT: ret entry: @@ -17,8 +15,6 @@ entry: define <4 x double> @insert_bitcast_v4f64(<4 x double> %a, i64 %b) nounwind { ; CHECK-LABEL: insert_bitcast_v4f64: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: movgr2fr.d $fa1, $a0 -; CHECK-NEXT: movfr2gr.d $a0, $fa1 ; CHECK-NEXT: xvinsgr2vr.d $xr0, $a0, 1 ; CHECK-NEXT: ret entry: diff --git a/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/bitcast-extract-element.ll b/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/bitcast-extract-element.ll index df4896d..9a40feb 100644 --- a/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/bitcast-extract-element.ll +++ b/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/bitcast-extract-element.ll @@ -4,8 +4,7 @@ define i32 @bitcast_extract_v4f32(<4 x float> %a) nounwind { ; CHECK-LABEL: bitcast_extract_v4f32: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: vreplvei.w $vr0, $vr0, 3 -; CHECK-NEXT: movfr2gr.s $a0, $fa0 +; CHECK-NEXT: vpickve2gr.w $a0, $vr0, 3 ; CHECK-NEXT: ret entry: %b = extractelement <4 x float> %a, i32 3 @@ -16,8 +15,7 @@ entry: define i64 @bitcast_extract_v2f64(<2 x double> %a) nounwind { ; CHECK-LABEL: bitcast_extract_v2f64: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: vreplvei.d $vr0, $vr0, 1 -; CHECK-NEXT: movfr2gr.d $a0, $fa0 +; CHECK-NEXT: vpickve2gr.d $a0, $vr0, 1 ; CHECK-NEXT: ret entry: %b = extractelement <2 x double> %a, i32 1 diff --git a/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/insert-bitcast-element.ll b/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/insert-bitcast-element.ll index a20d17e..c42e301 100644 --- a/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/insert-bitcast-element.ll +++ b/llvm/test/CodeGen/LoongArch/lsx/ir-instruction/insert-bitcast-element.ll @@ -4,8 +4,6 @@ define <4 x float> @insert_bitcast_v4f32(<4 x float> %a, i32 %b) nounwind { ; CHECK-LABEL: insert_bitcast_v4f32: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: movgr2fr.w $fa1, $a0 -; CHECK-NEXT: movfr2gr.s $a0, $fa1 ; CHECK-NEXT: vinsgr2vr.w $vr0, $a0, 1 ; CHECK-NEXT: ret entry: @@ -17,8 +15,6 @@ entry: define <2 x double> @insert_bitcast_v2f64(<2 x double> %a, i64 %b) nounwind { ; CHECK-LABEL: insert_bitcast_v2f64: ; CHECK: # %bb.0: # %entry -; CHECK-NEXT: movgr2fr.d $fa1, $a0 -; CHECK-NEXT: movfr2gr.d $a0, $fa1 ; CHECK-NEXT: vinsgr2vr.d $vr0, $a0, 1 ; CHECK-NEXT: ret entry: |