[llvm-branch-commits] [llvm] [LoongArch] Use INSERT_SUBREG of IMPLICIT_DEF to put an FP scalar in a LASX vector (PR #242330)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 13 05:55:56 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-loongarch
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
The patterns for vector_insert, scalar_to_vector and splat of an FP
scalar into a LASX vector used SUBREG_TO_REG to view the FPR as a vector
register. SUBREG_TO_REG means that the instruction defining the FPR also
defined the rest of the vector register, which is not the case. Only
element 0 is used, and scalar_to_vector leaves the other elements
undefined, which is what INSERT_SUBREG into an IMPLICIT_DEF expresses.
This changes the scheduling and register allocation in one test, but not
the number of instructions.
Co-Authored-By: Claude Opus 5.5 <noreply@<!-- -->anthropic.com>
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
---
Full diff: https://github.com/llvm/llvm-project/pull/242330.diff
2 Files Affected:
- (modified) llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td (+8-8)
- (modified) llvm/test/CodeGen/LoongArch/lasx/ir-instruction/extractelement.ll (+15-15)
``````````diff
diff --git a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
index 69e8de23cc9c9..d34738f75ca64 100644
--- a/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
+++ b/llvm/lib/Target/LoongArch/LoongArchLASXInstrInfo.td
@@ -2536,17 +2536,17 @@ def : Pat<(loongarch_xvinsve0 v8f32:$xd, v8f32:$xj, uimm3:$imm),
def : Pat<(loongarch_xvinsve0 v4f64:$xd, v4f64:$xj, uimm2:$imm),
(XVINSVE0_D v4f64:$xd, v4f64:$xj, uimm2:$imm)>;
def : Pat<(vector_insert v8f32:$xd, FPR32:$fj, uimm3:$imm),
- (XVINSVE0_W v8f32:$xd, (SUBREG_TO_REG FPR32:$fj, sub_32),
- uimm3:$imm)>;
+ (XVINSVE0_W v8f32:$xd,
+ (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32), uimm3:$imm)>;
def : Pat<(vector_insert v4f64:$xd, FPR64:$fj, uimm2:$imm),
- (XVINSVE0_D v4f64:$xd, (SUBREG_TO_REG FPR64:$fj, sub_64),
- uimm2:$imm)>;
+ (XVINSVE0_D v4f64:$xd,
+ (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64), uimm2:$imm)>;
// scalar_to_vector
def : Pat<(v8f32 (scalar_to_vector FPR32:$fj)),
- (SUBREG_TO_REG FPR32:$fj, sub_32)>;
+ (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32)>;
def : Pat<(v4f64 (scalar_to_vector FPR64:$fj)),
- (SUBREG_TO_REG FPR64:$fj, sub_64)>;
+ (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64)>;
// XVPICKVE2GR_W[U]
def : Pat<(loongarch_vpick_sext_elt v8i32:$xd, uimm3:$imm, i32),
@@ -2740,9 +2740,9 @@ def : Pat<(loongarch_xvreplve0 v8f32:$xj),
def : Pat<(loongarch_xvreplve0 v4f64:$xj),
(XVREPLVE0_D v4f64:$xj)>;
def : Pat<(lasxsplatf32 FPR32:$fj),
- (XVREPLVE0_W (SUBREG_TO_REG FPR32:$fj, sub_32))>;
+ (XVREPLVE0_W (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32))>;
def : Pat<(lasxsplatf64 FPR64:$fj),
- (XVREPLVE0_D (SUBREG_TO_REG FPR64:$fj, sub_64))>;
+ (XVREPLVE0_D (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64))>;
foreach vt = [v32i8, v16i16, v8i32, v4i64, v8f32, v4f64] in
def : Pat<(vt (loongarch_xvreplve0q LASX256:$xj)),
(XVREPLVE0_Q LASX256:$xj)>;
diff --git a/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/extractelement.ll b/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/extractelement.ll
index 3511c1d8b7222..9c340bf7a2378 100644
--- a/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/extractelement.ll
+++ b/llvm/test/CodeGen/LoongArch/lasx/ir-instruction/extractelement.ll
@@ -94,10 +94,10 @@ define void @extract_32xi8_idx(ptr %src, ptr %dst, i32 %idx) nounwind {
; LA64-LABEL: extract_32xi8_idx:
; LA64: # %bb.0:
; LA64-NEXT: xvld $xr0, $a0, 0
-; LA64-NEXT: xvpermi.q $xr1, $xr0, 1
; LA64-NEXT: bstrpick.d $a0, $a2, 31, 0
-; LA64-NEXT: movgr2fr.w $fa2, $a0
-; LA64-NEXT: xvshuf.b $xr0, $xr1, $xr0, $xr2
+; LA64-NEXT: movgr2fr.w $fa1, $a0
+; LA64-NEXT: xvpermi.q $xr2, $xr0, 1
+; LA64-NEXT: xvshuf.b $xr0, $xr2, $xr0, $xr1
; LA64-NEXT: xvstelm.b $xr0, $a1, 0, 0
; LA64-NEXT: ret
%v = load volatile <32 x i8>, ptr %src
@@ -119,11 +119,11 @@ define void @extract_16xi16_idx(ptr %src, ptr %dst, i32 %idx) nounwind {
; LA64-LABEL: extract_16xi16_idx:
; LA64: # %bb.0:
; LA64-NEXT: xvld $xr0, $a0, 0
-; LA64-NEXT: xvpermi.q $xr1, $xr0, 1
; LA64-NEXT: bstrpick.d $a0, $a2, 31, 0
-; LA64-NEXT: movgr2fr.w $fa2, $a0
-; LA64-NEXT: xvshuf.h $xr2, $xr1, $xr0
-; LA64-NEXT: xvstelm.h $xr2, $a1, 0, 0
+; LA64-NEXT: movgr2fr.w $fa1, $a0
+; LA64-NEXT: xvpermi.q $xr2, $xr0, 1
+; LA64-NEXT: xvshuf.h $xr1, $xr2, $xr0
+; LA64-NEXT: xvstelm.h $xr1, $a1, 0, 0
; LA64-NEXT: ret
%v = load volatile <16 x i16>, ptr %src
%e = extractelement <16 x i16> %v, i32 %idx
@@ -171,11 +171,11 @@ define void @extract_4xi64_idx(ptr %src, ptr %dst, i32 %idx) nounwind {
; LA64-LABEL: extract_4xi64_idx:
; LA64: # %bb.0:
; LA64-NEXT: xvld $xr0, $a0, 0
-; LA64-NEXT: xvpermi.q $xr1, $xr0, 1
; LA64-NEXT: bstrpick.d $a0, $a2, 31, 0
-; LA64-NEXT: movgr2fr.w $fa2, $a0
-; LA64-NEXT: xvshuf.d $xr2, $xr1, $xr0
-; LA64-NEXT: xvstelm.d $xr2, $a1, 0, 0
+; LA64-NEXT: movgr2fr.w $fa1, $a0
+; LA64-NEXT: xvpermi.q $xr2, $xr0, 1
+; LA64-NEXT: xvshuf.d $xr1, $xr2, $xr0
+; LA64-NEXT: xvstelm.d $xr1, $a1, 0, 0
; LA64-NEXT: ret
%v = load volatile <4 x i64>, ptr %src
%e = extractelement <4 x i64> %v, i32 %idx
@@ -219,11 +219,11 @@ define void @extract_4xdouble_idx(ptr %src, ptr %dst, i32 %idx) nounwind {
; LA64-LABEL: extract_4xdouble_idx:
; LA64: # %bb.0:
; LA64-NEXT: xvld $xr0, $a0, 0
-; LA64-NEXT: xvpermi.q $xr1, $xr0, 1
; LA64-NEXT: bstrpick.d $a0, $a2, 31, 0
-; LA64-NEXT: movgr2fr.w $fa2, $a0
-; LA64-NEXT: xvshuf.d $xr2, $xr1, $xr0
-; LA64-NEXT: xvstelm.d $xr2, $a1, 0, 0
+; LA64-NEXT: movgr2fr.w $fa1, $a0
+; LA64-NEXT: xvpermi.q $xr2, $xr0, 1
+; LA64-NEXT: xvshuf.d $xr1, $xr2, $xr0
+; LA64-NEXT: xvstelm.d $xr1, $a1, 0, 0
; LA64-NEXT: ret
%v = load volatile <4 x double>, ptr %src
%e = extractelement <4 x double> %v, i32 %idx
``````````
</details>
https://github.com/llvm/llvm-project/pull/242330
More information about the llvm-branch-commits
mailing list