Skip to content

Commit 5d6d982

Browse files
[AArch64] Generate zeroing forms of certain SVE2.2 instructions (11/11) (#116837)
SVE2.2 introduces instructions with predicated forms with zeroing of the inactive lanes. This allows in some cases to save a `movprfx` or a `mov` instruction when emitting code for `_x` or `_z` variants of intrinsics. This patch adds support for emitting the zeroing forms of certain `SXTB`, `UXTB`, `SXTH`, `UXTH`, `SXTW`, and `UXTW` instructions.
1 parent 754b946 commit 5d6d982

File tree

3 files changed

+1060
-8
lines changed

3 files changed

+1060
-8
lines changed

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,14 +4325,14 @@ let Predicates = [HasSVE2p2_or_SME2p2] in {
43254325
defm FNEG_ZPzZ : sve_int_un_pred_arit_bitwise_fp_z<0b101, "fneg", AArch64fneg_mt>;
43264326

43274327
// SVE2p2 integer unary arithmetic, zeroing predicate
4328-
defm SXTB_ZPzZ : sve_int_un_pred_arit_h_z<0b000, "sxtb">;
4329-
defm UXTB_ZPzZ : sve_int_un_pred_arit_h_z<0b001, "uxtb">;
4330-
defm SXTH_ZPzZ : sve_int_un_pred_arit_w_z<0b010, "sxth">;
4331-
defm UXTH_ZPzZ : sve_int_un_pred_arit_w_z<0b011, "uxth">;
4328+
defm SXTB_ZPzZ : sve_int_un_pred_arit_h_z<0b000, "sxtb", AArch64sxt_mt>;
4329+
defm UXTB_ZPzZ : sve_int_un_pred_arit_h_z<0b001, "uxtb", AArch64uxt_mt>;
4330+
defm SXTH_ZPzZ : sve_int_un_pred_arit_w_z<0b010, "sxth", AArch64sxt_mt>;
4331+
defm UXTH_ZPzZ : sve_int_un_pred_arit_w_z<0b011, "uxth", AArch64uxt_mt>;
43324332
defm ABS_ZPzZ : sve_int_un_pred_arit_z< 0b110, "abs", AArch64abs_mt>;
43334333
defm NEG_ZPzZ : sve_int_un_pred_arit_z< 0b111, "neg", AArch64neg_mt>;
4334-
def SXTW_ZPzZ_D : sve_int_un_pred_arit_z<0b11, 0b1000, "sxtw", ZPR64>;
4335-
def UXTW_ZPzZ_D : sve_int_un_pred_arit_z<0b11, 0b1010, "uxtw", ZPR64>;
4334+
defm SXTW_ZPzZ : sve_int_un_pred_arit_d_z<0b100, "sxtw", AArch64sxt_mt>;
4335+
defm UXTW_ZPzZ : sve_int_un_pred_arit_d_z<0b101, "uxtw", AArch64uxt_mt>;
43364336

43374337
// SVE predicate count
43384338
defm FIRSTP_XPP : sve_int_pcount_pred_tmp<0b001, "firstp">;

llvm/lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,17 @@ multiclass SVE_InReg_Extend_PassthruUndef<ValueType vt, SDPatternOperator op, Va
662662
(inst $PassThru, $Pg, $Src)>;
663663
}
664664

665+
multiclass SVE_InReg_Extend_PassthruUndefZero<ValueType vt, SDPatternOperator op, ValueType pt,
666+
ValueType inreg_vt, Instruction inst> {
667+
let AddedComplexity = 1 in {
668+
def : Pat<(vt (op pt:$Pg, vt:$Src, inreg_vt, (vt (SVEDup0Undef)))),
669+
(inst $Pg, $Src)>;
670+
671+
def : Pat<(vt (op (pt (SVEAllActive:$Pg)), vt:$Src, inreg_vt, (vt (SVEAny)))),
672+
(inst $Pg, $Src)>;
673+
}
674+
}
675+
665676
class SVE_Shift_DupImm_Pred_Pat<ValueType vt, SDPatternOperator op,
666677
ValueType pt, ValueType it,
667678
ComplexPattern cast, Instruction inst>
@@ -4930,10 +4941,14 @@ multiclass sve_int_un_pred_arit_h<bits<3> opc, string asm,
49304941
defm : SVE_InReg_Extend_PassthruUndef<nxv2i64, op, nxv2i1, nxv2i8, !cast<Pseudo>(NAME # _D_UNDEF)>;
49314942
}
49324943

4933-
multiclass sve_int_un_pred_arit_h_z<bits<3> opc, string asm> {
4944+
multiclass sve_int_un_pred_arit_h_z<bits<3> opc, string asm, SDPatternOperator op> {
49344945
def _H : sve_int_un_pred_arit_z<0b01, { opc, 0b0 }, asm, ZPR16>;
49354946
def _S : sve_int_un_pred_arit_z<0b10, { opc, 0b0 }, asm, ZPR32>;
49364947
def _D : sve_int_un_pred_arit_z<0b11, { opc, 0b0 }, asm, ZPR64>;
4948+
4949+
defm : SVE_InReg_Extend_PassthruUndefZero<nxv8i16, op, nxv8i1, nxv8i8, !cast<Instruction>(NAME # _H)>;
4950+
defm : SVE_InReg_Extend_PassthruUndefZero<nxv4i32, op, nxv4i1, nxv4i8, !cast<Instruction>(NAME # _S)>;
4951+
defm : SVE_InReg_Extend_PassthruUndefZero<nxv2i64, op, nxv2i1, nxv2i8, !cast<Instruction>(NAME # _D)>;
49374952
}
49384953

49394954
multiclass sve_int_un_pred_arit_w<bits<3> opc, string asm,
@@ -4953,9 +4968,12 @@ multiclass sve_int_un_pred_arit_w<bits<3> opc, string asm,
49534968
defm : SVE_InReg_Extend_PassthruUndef<nxv2i64, op, nxv2i1, nxv2i16, !cast<Pseudo>(NAME # _D_UNDEF)>;
49544969
}
49554970

4956-
multiclass sve_int_un_pred_arit_w_z<bits<3> opc, string asm> {
4971+
multiclass sve_int_un_pred_arit_w_z<bits<3> opc, string asm, SDPatternOperator op> {
49574972
def _S : sve_int_un_pred_arit_z<0b10, { opc, 0b0 }, asm, ZPR32>;
49584973
def _D : sve_int_un_pred_arit_z<0b11, { opc, 0b0 }, asm, ZPR64>;
4974+
4975+
defm : SVE_InReg_Extend_PassthruUndefZero<nxv4i32, op, nxv4i1, nxv4i16, !cast<Instruction>(NAME # _S)>;
4976+
defm : SVE_InReg_Extend_PassthruUndefZero<nxv2i64, op, nxv2i1, nxv2i16, !cast<Instruction>(NAME # _D)>;
49594977
}
49604978

49614979
multiclass sve_int_un_pred_arit_d<bits<3> opc, string asm,
@@ -4970,6 +4988,12 @@ multiclass sve_int_un_pred_arit_d<bits<3> opc, string asm,
49704988
defm : SVE_InReg_Extend_PassthruUndef<nxv2i64, op, nxv2i1, nxv2i32, !cast<Pseudo>(NAME # _D_UNDEF)>;
49714989
}
49724990

4991+
multiclass sve_int_un_pred_arit_d_z<bits<3> opc, string asm, SDPatternOperator op> {
4992+
def _D : sve_int_un_pred_arit_z<0b11, {opc, 0b0}, asm, ZPR64>;
4993+
4994+
defm : SVE_InReg_Extend_PassthruUndefZero<nxv2i64, op, nxv2i1, nxv2i32, !cast<Instruction>(NAME # _D)>;
4995+
}
4996+
49734997
multiclass sve_int_un_pred_arit_bitwise<bits<3> opc, string asm,
49744998
SDPatternOperator op> {
49754999
def _B : sve_int_un_pred_arit<0b00, { opc, 0b1 }, asm, ZPR8>,

0 commit comments

Comments
 (0)