https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/242329
fceil, ffloor, ftrunc and froundeven of an FP scalar are selected to a splat of element 0 of the FPR viewed as an LSX vector, a vector rounding instruction, and an extract of element 0. Only element 0 is used, so use INSERT_SUBREG into an IMPLICIT_DEF instead of SUBREG_TO_REG, which means that the instruction defining the FPR also defined the rest of the vector register. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- <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> >From 145177498bcfe35091b7bae0731e5436167134e3 Mon Sep 17 00:00:00 2001 From: Jay Foad <[email protected]> Date: Fri, 13 Nov 2026 13:46:05 +0000 Subject: [PATCH] [LoongArch] Use INSERT_SUBREG of IMPLICIT_DEF for scalar FP rounding via LSX. NFC fceil, ffloor, ftrunc and froundeven of an FP scalar are selected to a splat of element 0 of the FPR viewed as an LSX vector, a vector rounding instruction, and an extract of element 0. Only element 0 is used, so use INSERT_SUBREG into an IMPLICIT_DEF instead of SUBREG_TO_REG, which means that the instruction defining the FPR also defined the rest of the vector register. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../Target/LoongArch/LoongArchLSXInstrInfo.td | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td index 42599cd6f2cda..c4ccd06ed6ca6 100644 --- a/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td +++ b/llvm/lib/Target/LoongArch/LoongArchLSXInstrInfo.td @@ -3508,28 +3508,36 @@ def : Pat<(loongarch_vfrsqrte v2f64:$src), // Vector floating-point conversion def : Pat<(f32 (fceil FPR32:$fj)), (f32 (EXTRACT_SUBREG (VFRINTRP_S (VREPLVEI_W - (SUBREG_TO_REG FPR32:$fj, sub_32), 0)), sub_32))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32), 0)), + sub_32))>; def : Pat<(f64 (fceil FPR64:$fj)), (f64 (EXTRACT_SUBREG (VFRINTRP_D (VREPLVEI_D - (SUBREG_TO_REG FPR64:$fj, sub_64), 0)), sub_64))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64), 0)), + sub_64))>; def : Pat<(f32 (ffloor FPR32:$fj)), (f32 (EXTRACT_SUBREG (VFRINTRM_S (VREPLVEI_W - (SUBREG_TO_REG FPR32:$fj, sub_32), 0)), sub_32))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32), 0)), + sub_32))>; def : Pat<(f64 (ffloor FPR64:$fj)), (f64 (EXTRACT_SUBREG (VFRINTRM_D (VREPLVEI_D - (SUBREG_TO_REG FPR64:$fj, sub_64), 0)), sub_64))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64), 0)), + sub_64))>; def : Pat<(f32 (ftrunc FPR32:$fj)), (f32 (EXTRACT_SUBREG (VFRINTRZ_S (VREPLVEI_W - (SUBREG_TO_REG FPR32:$fj, sub_32), 0)), sub_32))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32), 0)), + sub_32))>; def : Pat<(f64 (ftrunc FPR64:$fj)), (f64 (EXTRACT_SUBREG (VFRINTRZ_D (VREPLVEI_D - (SUBREG_TO_REG FPR64:$fj, sub_64), 0)), sub_64))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64), 0)), + sub_64))>; def : Pat<(f32 (froundeven FPR32:$fj)), (f32 (EXTRACT_SUBREG (VFRINTRNE_S (VREPLVEI_W - (SUBREG_TO_REG FPR32:$fj, sub_32), 0)), sub_32))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR32:$fj, sub_32), 0)), + sub_32))>; def : Pat<(f64 (froundeven FPR64:$fj)), (f64 (EXTRACT_SUBREG (VFRINTRNE_D (VREPLVEI_D - (SUBREG_TO_REG FPR64:$fj, sub_64), 0)), sub_64))>; + (INSERT_SUBREG (IMPLICIT_DEF), FPR64:$fj, sub_64), 0)), + sub_64))>; defm : PatVrF<fceil, "VFRINTRP">; defm : PatVrF<ffloor, "VFRINTRM">; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
