Skip to content

Commit 0403e98

Browse files
committed
Add more generic half/bfloat tests (NFC)
1 parent 816eb9e commit 0403e98

File tree

3 files changed

+296
-0
lines changed

3 files changed

+296
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
; Same as `bfloat.ll`, but for `fneg`, `fabs`, `copysign` and `fma`.
2+
; Can be merged back into `bfloat.ll` once they have the same platform coverage.
3+
; Once all targets are fixed, the `CHECK-*` prefixes should all be merged into a single `CHECK` prefix and the `BAD-*` prefixes should be removed.
4+
5+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-apple-darwin | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,CHECK-FMA %}
6+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,CHECK-FMA %}
7+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,CHECK-FMA %}
8+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=arm64ec-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,CHECK-FMA %}
9+
; RUN: %if amdgpu-registered-target %{ llc %s -o - -mtriple=amdgcn-amd-amdhsa | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,CHECK-FMA %}
10+
; RUN: %if arc-registered-target %{ llc %s -o - -mtriple=arc-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
11+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=arm-unknown-linux-gnueabi | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
12+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=thumbv7em-none-eabi | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
13+
; RUN: %if avr-registered-target %{ llc %s -o - -mtriple=avr-none | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
14+
; FIXME: BPF has a compiler error
15+
; RUN: %if csky-registered-target %{ llc %s -o - -mtriple=csky-unknown-linux-gnuabiv2 | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
16+
; FIXME: hard float csky crashes
17+
; FIXME: directx has a compiler error
18+
; FIXME: hexagon crashes
19+
; RUN: %if lanai-registered-target %{ llc %s -o - -mtriple=lanai-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
20+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
21+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
22+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch64-unknown-linux-gnu -mattr=+f | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
23+
; RUN: %if m68k-registered-target %{ llc %s -o - -mtriple=m68k-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
24+
; FIXME: mips crashes
25+
; RUN: %if msp430-registered-target %{ llc %s -o - -mtriple=msp430-none-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
26+
; RUN: %if nvptx-registered-target %{ llc %s -o - -mtriple=nvptx64-nvidia-cuda | FileCheck %s --check-prefixes=NOCRASH %}
27+
; FIXME: powerpc crashes
28+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
29+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
30+
; FIXME: sparc crashes
31+
; FIXME: spirv crashes
32+
; FIXME: s390x crashes
33+
; FIXME: ve crashes
34+
; FIXME: wasm crashes
35+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=i686-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,BAD-FMA %}
36+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,BAD-FMA %}
37+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS,CHECK-COPYSIGN,BAD-FMA %}
38+
; RUN: %if xcore-registered-target %{ llc %s -o - -mtriple=xcore-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS,CHECK-COPYSIGN,BAD-FMA %}
39+
; RUN: %if xtensa-registered-target %{ llc %s -o - -mtriple=xtensa-none-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG,CHECK-ABS,BAD-COPYSIGN,CHECK-FMA %}
40+
41+
; Note that arm64ec labels are quoted, hence the `{{"?}}:`.
42+
43+
; Codegen tests don't work the same for graphics targets. Add a dummy directive
44+
; for filecheck, just make sure we don't crash.
45+
; NOCRASH: {{.*}}
46+
47+
; fneg, fabs and copysign all need to not quieten signalling NaNs, so should not call any conversion functions which do.
48+
; These tests won't catch cases where the everything is done using native instructions instead of builtins.
49+
50+
define void @test_fneg(ptr %p1, ptr %p2) #0 {
51+
; ALL-LABEL: test_fneg{{"?}}:
52+
; CHECK-NEG-NOT: __extend
53+
; CHECK-NEG-NOT: __trunc
54+
; CHECK-NEG-NOT: __gnu
55+
; CHECK-NEG-NOT: __aeabi
56+
; BAD-NEG: __truncsfbf2
57+
%v = load bfloat, ptr %p1
58+
%res = fneg bfloat %v
59+
store bfloat %res, ptr %p2
60+
ret void
61+
}
62+
63+
define void @test_fabs(ptr %p1, ptr %p2) {
64+
; ALL-LABEL: test_fabs{{"?}}:
65+
; CHECK-ABS-NOT: __extend
66+
; CHECK-ABS-NOT: __trunc
67+
; CHECK-ABS-NOT: __gnu
68+
; CHECK-ABS-NOT: __aeabi
69+
; BAD-ABS: __truncsfbf2
70+
%a = load bfloat, ptr %p1
71+
%r = call bfloat @llvm.fabs.f16(bfloat %a)
72+
store bfloat %r, ptr %p2
73+
ret void
74+
}
75+
76+
define void @test_copysign(ptr %p1, ptr %p2, ptr %p3) {
77+
; ALL-LABEL: test_copysign{{"?}}:
78+
; CHECK-COPYSIGN-NOT: __extend
79+
; CHECK-COPYSIGN-NOT: __trunc
80+
; CHECK-COPYSIGN-NOT: __gnu
81+
; CHECK-COPYSIGN-NOT: __aeabi
82+
; BAD-COPYSIGN: __truncsfbf2
83+
%a = load bfloat, ptr %p1
84+
%b = load bfloat, ptr %p2
85+
%r = call bfloat @llvm.copysign.f16(bfloat %a, bfloat %b)
86+
store bfloat %r, ptr %p3
87+
ret void
88+
}
89+
90+
; There is no floating-point type LLVM supports that is large enough to promote bfloat FMA to
91+
; without causing double rounding issues. This checks for libcalls to f32/f64 fma and truncating
92+
; f32/f64 to bf16. See https://github.com/llvm/llvm-project/issues/131531
93+
94+
define void @test_fma(ptr %p1, ptr %p2, ptr %p3, ptr %p4) {
95+
; ALL-LABEL: test_fma{{"?}}:
96+
; CHECK-FMA-NOT: {{\bfmaf?\b}}
97+
; CHECK-FMA-NOT: __truncsfbf2
98+
; CHECK-FMA-NOT: __truncdfbf2
99+
; BAD-FMA: {{__truncsfbf2|\bfmaf?\b}}
100+
%a = load bfloat, ptr %p1
101+
%b = load bfloat, ptr %p2
102+
%c = load bfloat, ptr %p3
103+
%r = call bfloat @llvm.fma.f16(bfloat %a, bfloat %b, bfloat %c)
104+
store bfloat %r, ptr %p4
105+
ret void
106+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
; Simple cross-platform smoke checks for basic bf16 operations.
2+
;
3+
; There shouldn't be any architectures that crash when trying to use `bfloat`;
4+
; check that here. Additionally do a small handful of smoke tests that work
5+
; well cross-platform.
6+
7+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-apple-darwin | FileCheck %s --check-prefixes=ALL,CHECK %}
8+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK %}
9+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
10+
; FIXME: arm64ec crashes when passing/returning bfloat
11+
; RUN: %if amdgpu-registered-target %{ llc %s -o - -mtriple=amdgcn-amd-amdhsa | FileCheck %s --check-prefixes=ALL,CHECK %}
12+
; RUN: %if arc-registered-target %{ llc %s -o - -mtriple=arc-elf | FileCheck %s --check-prefixes=ALL,CHECK %}
13+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=arm-unknown-linux-gnueabi | FileCheck %s --check-prefixes=ALL,CHECK %}
14+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=thumbv7em-none-eabi | FileCheck %s --check-prefixes=ALL,CHECK %}
15+
; RUN: %if avr-registered-target %{ llc %s -o - -mtriple=avr-none | FileCheck %s --check-prefixes=ALL,CHECK %}
16+
; RUN: %if bpf-registered-target %{ llc %s -o - -mtriple=bpfel | FileCheck %s --check-prefixes=ALL,CHECK %}
17+
; RUN: %if csky-registered-target %{ llc %s -o - -mtriple=csky-unknown-linux-gnuabiv2 | FileCheck %s --check-prefixes=ALL,CHECK %}
18+
; FIXME: hard float csky crashes
19+
; RUN: %if directx-registered-target %{ llc %s -o - -mtriple=dxil-pc-shadermodel6.3-library | FileCheck %s --check-prefixes=NOCRASH %}
20+
; FIXME: hexagon crashes
21+
; RUN: %if lanai-registered-target %{ llc %s -o - -mtriple=lanai-unknown-unknown | FileCheck %s --check-prefixes=ALL,CHECK %}
22+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
23+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
24+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch64-unknown-linux-gnu -mattr=+f | FileCheck %s --check-prefixes=ALL,CHECK %}
25+
; RUN: %if m68k-registered-target %{ llc %s -o - -mtriple=m68k-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
26+
; FIXME: mips crashes
27+
; RUN: %if msp430-registered-target %{ llc %s -o - -mtriple=msp430-none-elf | FileCheck %s --check-prefixes=ALL,CHECK %}
28+
; RUN: %if nvptx-registered-target %{ llc %s -o - -mtriple=nvptx64-nvidia-cuda | FileCheck %s --check-prefixes=NOCRASH %}
29+
; FIXME: powerpc crashes
30+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
31+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
32+
; FIXME: sparc crashes
33+
; FIXME: spirv crashes
34+
; FIXME: s390x crashes
35+
; FIXME: ve crashes
36+
; FIXME: wasm crashes
37+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=i686-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD %}
38+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK %}
39+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK %}
40+
; RUN: %if xcore-registered-target %{ llc %s -o - -mtriple=xcore-unknown-unknown | FileCheck %s --check-prefixes=ALL,CHECK %}
41+
; RUN: %if xtensa-registered-target %{ llc %s -o - -mtriple=xtensa-none-elf | FileCheck %s --check-prefixes=ALL,CHECK %}
42+
43+
; Note that arm64ec labels are quoted, hence the `{{"?}}:`.
44+
45+
; Codegen tests don't work the same for graphics targets. Add a dummy directive
46+
; for filecheck, just make sure we don't crash.
47+
; NOCRASH: {{.*}}
48+
49+
; All backends need to be able to bitcast without converting to another format,
50+
; so we assert against libcalls (specifically __truncsfbf2). This won't catch hardware conversions.
51+
52+
define bfloat @from_bits(i16 %bits) nounwind {
53+
; ALL-LABEL: from_bits{{"?}}:
54+
; ALL-NOT: __extend
55+
; ALL-NOT: __trunc
56+
; ALL-NOT: __gnu
57+
%f = bitcast i16 %bits to bfloat
58+
ret bfloat %f
59+
}
60+
61+
define i16 @to_bits(bfloat %f) nounwind {
62+
; ALL-LABEL: to_bits{{"?}}:
63+
; CHECK-NOT: __extend
64+
; CHECK-NOT: __trunc
65+
; CHECK-NOT: __gnu
66+
; BAD: __truncsfbf2
67+
%bits = bitcast bfloat %f to i16
68+
ret i16 %bits
69+
}
70+
71+
define bfloat @check_freeze(bfloat %f) nounwind {
72+
; ALL-LABEL: check_freeze{{"?}}:
73+
%t0 = freeze bfloat %f
74+
ret bfloat %t0
75+
}

0 commit comments

Comments
 (0)