Skip to content

Commit 37a92f9

Browse files
author
Dinar Temirbulatov
authored
[AArch64][SVE2] SVE2 NBSL instruction lowering. (#89732)
Allow to fold BSL/EOR instuctions to NBSL instruction for scalable vectors.
1 parent 72c373b commit 37a92f9

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ def AArch64vsli : SDNode<"AArch64ISD::VSLI", SDT_AArch64vshiftinsert>;
746746
def AArch64vsri : SDNode<"AArch64ISD::VSRI", SDT_AArch64vshiftinsert>;
747747

748748
def AArch64bsp: SDNode<"AArch64ISD::BSP", SDT_AArch64trivec>;
749+
def AArch64nbsl: PatFrag<(ops node:$Op1, node:$Op2, node:$Op3),
750+
(vnot (AArch64bsp node:$Op1, node:$Op2, node:$Op3))>;
749751

750752
def AArch64cmeq: SDNode<"AArch64ISD::CMEQ", SDT_AArch64binvec>;
751753
def AArch64cmge: SDNode<"AArch64ISD::CMGE", SDT_AArch64binvec>;

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,7 @@ let Predicates = [HasSVE2orSME] in {
37603760
defm BSL_ZZZZ : sve2_int_bitwise_ternary_op<0b001, "bsl", int_aarch64_sve_bsl, AArch64bsp>;
37613761
defm BSL1N_ZZZZ : sve2_int_bitwise_ternary_op<0b011, "bsl1n", int_aarch64_sve_bsl1n>;
37623762
defm BSL2N_ZZZZ : sve2_int_bitwise_ternary_op<0b101, "bsl2n", int_aarch64_sve_bsl2n>;
3763-
defm NBSL_ZZZZ : sve2_int_bitwise_ternary_op<0b111, "nbsl", int_aarch64_sve_nbsl>;
3763+
defm NBSL_ZZZZ : sve2_int_bitwise_ternary_op<0b111, "nbsl", int_aarch64_sve_nbsl, AArch64nbsl>;
37643764

37653765
// SVE2 bitwise xor and rotate right by immediate
37663766
defm XAR_ZZZI : sve2_int_rotate_right_imm<"xar", int_aarch64_sve_xar>;

llvm/test/CodeGen/AArch64/sve2-bsl.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,55 @@ define <vscale x 4 x i32> @no_bsl_fold(<vscale x 4 x i32> %a, <vscale x 4 x i32>
4141
%c = or <vscale x 4 x i32> %1, %2
4242
ret <vscale x 4 x i32> %c
4343
}
44+
45+
define <vscale x 16 x i8> @nbsl_i8(<vscale x 16 x i8> %a, <vscale x 16 x i8> %b) {
46+
; CHECK-LABEL: nbsl_i8:
47+
; CHECK: // %bb.0:
48+
; CHECK-NEXT: mov z2.b, #127 // =0x7f
49+
; CHECK-NEXT: nbsl z0.d, z0.d, z1.d, z2.d
50+
; CHECK-NEXT: ret
51+
%1 = and <vscale x 16 x i8> %a, splat(i8 127)
52+
%2 = and <vscale x 16 x i8> %b, splat(i8 -128)
53+
%3 = or <vscale x 16 x i8> %1, %2
54+
%4 = xor <vscale x 16 x i8> %3, splat(i8 -1)
55+
ret <vscale x 16 x i8> %4
56+
}
57+
58+
define <vscale x 8 x i16> @nbsl_i16(<vscale x 8 x i16> %a, <vscale x 8 x i16> %b) {
59+
; CHECK-LABEL: nbsl_i16:
60+
; CHECK: // %bb.0:
61+
; CHECK-NEXT: mov z2.h, #32767 // =0x7fff
62+
; CHECK-NEXT: nbsl z0.d, z0.d, z1.d, z2.d
63+
; CHECK-NEXT: ret
64+
%1 = and <vscale x 8 x i16> %a, splat(i16 32767)
65+
%2 = and <vscale x 8 x i16> %b, splat(i16 -32768)
66+
%3 = or <vscale x 8 x i16> %1, %2
67+
%4 = xor <vscale x 8 x i16> %3, splat(i16 -1)
68+
ret <vscale x 8 x i16> %4
69+
}
70+
71+
define <vscale x 4 x i32> @nbsl_i32(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b) {
72+
; CHECK-LABEL: nbsl_i32:
73+
; CHECK: // %bb.0:
74+
; CHECK-NEXT: mov z2.s, #0x7fffffff
75+
; CHECK-NEXT: nbsl z0.d, z0.d, z1.d, z2.d
76+
; CHECK-NEXT: ret
77+
%1 = and <vscale x 4 x i32> %a, splat(i32 2147483647)
78+
%2 = and <vscale x 4 x i32> %b, splat(i32 -2147483648)
79+
%3 = or <vscale x 4 x i32> %1, %2
80+
%4 = xor <vscale x 4 x i32> %3, splat(i32 -1)
81+
ret <vscale x 4 x i32> %4
82+
}
83+
84+
define <vscale x 2 x i64> @nbsl_i64(<vscale x 2 x i64> %a, <vscale x 2 x i64> %b) {
85+
; CHECK-LABEL: nbsl_i64:
86+
; CHECK: // %bb.0:
87+
; CHECK-NEXT: mov z2.d, #0x7fffffffffffffff
88+
; CHECK-NEXT: nbsl z0.d, z0.d, z1.d, z2.d
89+
; CHECK-NEXT: ret
90+
%1 = and <vscale x 2 x i64> %a, splat(i64 9223372036854775807)
91+
%2 = and <vscale x 2 x i64> %b, splat(i64 -9223372036854775808)
92+
%3 = or <vscale x 2 x i64> %1, %2
93+
%4 = xor <vscale x 2 x i64> %3, splat(i64 -1)
94+
ret <vscale x 2 x i64> %4
95+
}

0 commit comments

Comments
 (0)