Masked store of <8 x bf16> is not lowered
With v9.2a, masked stores of bf16 cause an ICE: https://godbolt.org/z/PsPbdzTM7
llc --mtriple=aarch64-none-linux-gnu -O2 aarch64-bf16-mstore.ll -o -
LLVM ERROR: Cannot select: t12: ch = masked_store<(store unknown-size into %ir.P, align 2)> t0, t2, t4, undef:i64, t14
t2: v8bf16,ch = CopyFromReg t0, Register:v8bf16 %0
t4: i64,ch = CopyFromReg t0, Register:i64 %1
t14: v8i16 = setcc t6, t8, seteq:ch
t6: v8i16,ch = CopyFromReg t0, Register:v8i16 %2
t8: v8i16,ch = CopyFromReg t0, Register:v8i16 %3
In function: f_bf16
The source code:
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-none-linux-gnu"
define void @f_f16(<8 x half> %V, ptr noundef %P, <8 x i16> %X, <8 x i16> %Y) #1 {
entry:
%cmp = icmp eq <8 x i16> %X, %Y
tail call void @llvm.masked.store(<8 x half> %V, ptr align 2 %P, <8 x i1> %cmp)
ret void
}
define void @f_i16(<8 x i16> %V, ptr noundef %P, <8 x i16> %X, <8 x i16> %Y) #1 {
entry:
%cmp = icmp eq <8 x i16> %X, %Y
tail call void @llvm.masked.store(<8 x i16> %V, ptr align 2 %P, <8 x i1> %cmp)
ret void
}
define void @f_bf16(<8 x bfloat> %V, ptr noundef %P, <8 x i16> %X, <8 x i16> %Y) #1 {
entry:
%cmp = icmp eq <8 x i16> %X, %Y
tail call void @llvm.masked.store.v8bf16.p0(<8 x bfloat> %V, ptr align 2 %P, <8 x i1> %cmp)
ret void
}
attributes #1 = { mustprogress "target-cpu"="generic" "target-features"="+bf16,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8.7a,+v8a,+v9.1a,+v9.2a,+v9a" }
Masked stores of other 16-bit types (i16, half) are lowered to st1h { z0.h }, p1, [x0], they are in the same example.
We generate such masked stores with the Ripple front-end.
LLVM commit: 0212229ac05d60314db7dfb8ae89c11a015bb7bc
@llvm/issue-subscribers-backend-aarch64
Author: Alexey Karyakin (quic-akaryaki)
llc --mtriple=aarch64-none-linux-gnu -O2 aarch64-bf16-mstore.ll -o -
LLVM ERROR: Cannot select: t12: ch = masked_store<(store unknown-size into %ir.P, align 2)> t0, t2, t4, undef:i64, t14
t2: v8bf16,ch = CopyFromReg t0, Register:v8bf16 %0
t4: i64,ch = CopyFromReg t0, Register:i64 %1
t14: v8i16 = setcc t6, t8, seteq:ch
t6: v8i16,ch = CopyFromReg t0, Register:v8i16 %2
t8: v8i16,ch = CopyFromReg t0, Register:v8i16 %3
In function: f_bf16
The source code:
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-none-linux-gnu"
define void @<!-- -->f_f16(<8 x half> %V, ptr noundef %P, <8 x i16> %X, <8 x i16> %Y) #<!-- -->1 {
entry:
%cmp = icmp eq <8 x i16> %X, %Y
tail call void @<!-- -->llvm.masked.store(<8 x half> %V, ptr align 2 %P, <8 x i1> %cmp)
ret void
}
define void @<!-- -->f_i16(<8 x i16> %V, ptr noundef %P, <8 x i16> %X, <8 x i16> %Y) #<!-- -->1 {
entry:
%cmp = icmp eq <8 x i16> %X, %Y
tail call void @<!-- -->llvm.masked.store(<8 x i16> %V, ptr align 2 %P, <8 x i1> %cmp)
ret void
}
define void @<!-- -->f_bf16(<8 x bfloat> %V, ptr noundef %P, <8 x i16> %X, <8 x i16> %Y) #<!-- -->1 {
entry:
%cmp = icmp eq <8 x i16> %X, %Y
tail call void @<!-- -->llvm.masked.store.v8bf16.p0(<8 x bfloat> %V, ptr align 2 %P, <8 x i1> %cmp)
ret void
}
attributes #<!-- -->1 = { mustprogress "target-cpu"="generic" "target-features"="+bf16,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8.7a,+v8a,+v9.1a,+v9.2a,+v9a" }
Masked stores of other 16-bit types (i16, half) are lowered to st1h { z0.h }, p1, [x0], they are in the same example.
We generate such masked stores with the Ripple front-end.
LLVM commit: 0212229ac05d60314db7dfb8ae89c11a015bb7bc
We can hopefully use this for the other issues in BF16 fixed-length vectorization too. The ones I know of are:
- #208744 Loads / stores.
- #209194 FPExt (already on the branch).
- #209411 FPTrunc.
- #210273 Masked gather / scatter.
/cherry-pick 50f2b9443d23eba757c3c0f42eef71e0f9721b15
/pull-request llvm/llvm-project#210264
/cherry-pick b9869c8c920a7dfa983e215bc30729b13d8b353b
/cherry-pick 50f2b9443d23eba757c3c0f42eef71e0f9721b15
It looks like the cherry picks didn't work like I expected - The second overrode the first in stead of creating a new one. I am trying to set it back and will create the other elsewhere.
Should be fixed in clang23. Thanks all.