Skip to content

Commit 478b794

Browse files
davemgreenmahesh-attarde
authored andcommitted
[AArch64] Add missing bitcast patterns for bf16<->f16 converts. (llvm#159816)
This fills in the missing patterns for bicasting v4f16 to/from v4bf16, and v8f16 to/from v8f16. Clean up some formatting whilst here. Fixes llvm#159772
1 parent 8ca8ea2 commit 478b794

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9907,8 +9907,14 @@ def : Pat<(v4bf16 (bitconvert (v2f32 FPR64:$src))),
99079907
def : Pat<(v4bf16 (bitconvert (v1f64 FPR64:$src))),
99089908
(v4bf16 (REV64v4i16 FPR64:$src))>;
99099909
}
9910-
def : Pat<(v4f16 (bitconvert (v4i16 FPR64:$src))), (v4f16 FPR64:$src)>;
9911-
def : Pat<(v4bf16 (bitconvert (v4i16 FPR64:$src))), (v4bf16 FPR64:$src)>;
9910+
def : Pat<(v4f16 (bitconvert (v4i16 FPR64:$src))),
9911+
(v4f16 FPR64:$src)>;
9912+
def : Pat<(v4f16 (bitconvert (v4bf16 FPR64:$src))),
9913+
(v4f16 FPR64:$src)>;
9914+
def : Pat<(v4bf16 (bitconvert (v4i16 FPR64:$src))),
9915+
(v4bf16 FPR64:$src)>;
9916+
def : Pat<(v4bf16 (bitconvert (v4f16 FPR64:$src))),
9917+
(v4bf16 FPR64:$src)>;
99129918

99139919
let Predicates = [IsLE] in {
99149920
def : Pat<(v8i8 (bitconvert (v1i64 FPR64:$src))), (v8i8 FPR64:$src)>;
@@ -10236,8 +10242,14 @@ def : Pat<(v8bf16 (bitconvert (v2f64 FPR128:$src))),
1023610242
def : Pat<(v8bf16 (bitconvert (v4f32 FPR128:$src))),
1023710243
(v8bf16 (REV32v8i16 FPR128:$src))>;
1023810244
}
10239-
def : Pat<(v8f16 (bitconvert (v8i16 FPR128:$src))), (v8f16 FPR128:$src)>;
10240-
def : Pat<(v8bf16 (bitconvert (v8i16 FPR128:$src))), (v8bf16 FPR128:$src)>;
10245+
def : Pat<(v8f16 (bitconvert (v8i16 FPR128:$src))),
10246+
(v8f16 FPR128:$src)>;
10247+
def : Pat<(v8bf16 (bitconvert (v8i16 FPR128:$src))),
10248+
(v8bf16 FPR128:$src)>;
10249+
def : Pat<(v8f16 (bitconvert (v8bf16 FPR128:$src))),
10250+
(v8f16 FPR128:$src)>;
10251+
def : Pat<(v8bf16 (bitconvert (v8f16 FPR128:$src))),
10252+
(v8bf16 FPR128:$src)>;
1024110253

1024210254
let Predicates = [IsLE] in {
1024310255
def : Pat<(v16i8 (bitconvert (f128 FPR128:$src))), (v16i8 FPR128:$src)>;

llvm/test/CodeGen/AArch64/bf16-vector-bitcast.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ entry:
1111
ret <4 x i16> %1
1212
}
1313

14+
define <4 x half> @v4bf16_to_v4f16(float, <4 x bfloat> %a) nounwind {
15+
; CHECK-LABEL: v4bf16_to_v4f16:
16+
; CHECK: // %bb.0: // %entry
17+
; CHECK-NEXT: fmov d0, d1
18+
; CHECK-NEXT: ret
19+
entry:
20+
%1 = bitcast <4 x bfloat> %a to <4 x half>
21+
ret <4 x half> %1
22+
}
23+
1424
define <2 x i32> @v4bf16_to_v2i32(float, <4 x bfloat> %a) nounwind {
1525
; CHECK-LABEL: v4bf16_to_v2i32:
1626
; CHECK: // %bb.0: // %entry
@@ -82,6 +92,16 @@ entry:
8292
ret <4 x bfloat> %1
8393
}
8494

95+
define <4 x bfloat> @v4f16_to_v4bf16(float, <4 x half> %a) nounwind {
96+
; CHECK-LABEL: v4f16_to_v4bf16:
97+
; CHECK: // %bb.0: // %entry
98+
; CHECK-NEXT: fmov d0, d1
99+
; CHECK-NEXT: ret
100+
entry:
101+
%1 = bitcast <4 x half> %a to <4 x bfloat>
102+
ret <4 x bfloat> %1
103+
}
104+
85105
define <4 x bfloat> @v2i32_to_v4bf16(float, <2 x i32> %a) nounwind {
86106
; CHECK-LABEL: v2i32_to_v4bf16:
87107
; CHECK: // %bb.0: // %entry
@@ -152,6 +172,16 @@ entry:
152172
ret <8 x i16> %1
153173
}
154174

175+
define <8 x half> @v8bf16_to_v8f16(float, <8 x bfloat> %a) nounwind {
176+
; CHECK-LABEL: v8bf16_to_v8f16:
177+
; CHECK: // %bb.0: // %entry
178+
; CHECK-NEXT: mov v0.16b, v1.16b
179+
; CHECK-NEXT: ret
180+
entry:
181+
%1 = bitcast <8 x bfloat> %a to <8 x half>
182+
ret <8 x half> %1
183+
}
184+
155185
define <4 x i32> @v8bf16_to_v4i32(float, <8 x bfloat> %a) nounwind {
156186
; CHECK-LABEL: v8bf16_to_v4i32:
157187
; CHECK: // %bb.0: // %entry
@@ -202,6 +232,16 @@ entry:
202232
ret <8 x bfloat> %1
203233
}
204234

235+
define <8 x bfloat> @v8f16_to_v8bf16(float, <8 x half> %a) nounwind {
236+
; CHECK-LABEL: v8f16_to_v8bf16:
237+
; CHECK: // %bb.0: // %entry
238+
; CHECK-NEXT: mov v0.16b, v1.16b
239+
; CHECK-NEXT: ret
240+
entry:
241+
%1 = bitcast <8 x half> %a to <8 x bfloat>
242+
ret <8 x bfloat> %1
243+
}
244+
205245
define <8 x bfloat> @v4i32_to_v8bf16(float, <4 x i32> %a) nounwind {
206246
; CHECK-LABEL: v4i32_to_v8bf16:
207247
; CHECK: // %bb.0: // %entry

0 commit comments

Comments
 (0)