Skip to content

Commit 9e3fae8

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

File tree

3 files changed

+277
-0
lines changed

3 files changed

+277
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 %}
6+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS %}
7+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS %}
8+
; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=arm64ec-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS %}
9+
; RUN: %if amdgpu-registered-target %{ llc %s -o - -mtriple=amdgcn-amd-amdhsa | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS %}
10+
; RUN: %if arc-registered-target %{ llc %s -o - -mtriple=arc-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
11+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=arm-unknown-linux-gnueabi | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
12+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=thumbv7em-none-eabi | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
13+
; RUN: %if avr-registered-target %{ llc %s -o - -mtriple=avr-none | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
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 %}
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 %}
20+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
21+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
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 %}
23+
; RUN: %if m68k-registered-target %{ llc %s -o - -mtriple=m68k-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
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 %}
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 %}
29+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
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 %}
36+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS %}
37+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG,CHECK-ABS %}
38+
; RUN: %if xcore-registered-target %{ llc %s -o - -mtriple=xcore-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG,BAD-ABS %}
39+
; RUN: %if xtensa-registered-target %{ llc %s -o - -mtriple=xtensa-none-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG,CHECK-ABS %}
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+
; ALL-NOT: __extend
79+
; ALL-NOT: __trunc
80+
; ALL-NOT: __gnu
81+
; ALL-NOT: __aeabi
82+
%a = load bfloat, ptr %p1
83+
%b = load bfloat, ptr %p2
84+
%r = call bfloat @llvm.copysign.f16(bfloat %a, bfloat %b)
85+
store bfloat %r, ptr %p3
86+
ret void
87+
}
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+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
; Same as `half.ll`, but for `fneg`, `fabs`, `copysign` and `fma`.
2+
; Can be merged back into `half.ll` once BPF doesn't have a compiler error.
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-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-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-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-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-ABS,CHECK-COPYSIGN,CHECK-FMA %}
10+
; RUN: %if arc-registered-target %{ llc %s -o - -mtriple=arc-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
11+
; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=arm-unknown-linux-gnueabi | FileCheck %s --check-prefixes=ALL,BAD-NEG-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-ABS,CHECK-COPYSIGN,BAD-FMA %}
13+
; RUN: %if avr-registered-target %{ llc %s -o - -mtriple=avr-none | FileCheck %s --check-prefixes=ALL,BAD-NEG-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-ABS,BAD-COPYSIGN,BAD-FMA %}
16+
; RUN: %if csky-registered-target %{ llc %s -o - -mtriple=csky-unknown-linux-gnuabiv2 -mcpu=ck860fv -mattr=+hard-float | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
17+
; FIXME: directx has a compiler error
18+
; RUN: %if hexagon-registered-target %{ llc %s -o - -mtriple=hexagon-unknown-linux-musl | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
19+
; RUN: %if lanai-registered-target %{ llc %s -o - -mtriple=lanai-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
20+
; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-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-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-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-ABS,BAD-COPYSIGN,BAD-FMA %}
24+
; RUN: %if mips-registered-target %{ llc %s -o - -mtriple=mips-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
25+
; RUN: %if mips-registered-target %{ llc %s -o - -mtriple=mips64-unknown-linux-gnuabi64 | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
26+
; RUN: %if mips-registered-target %{ llc %s -o - -mtriple=mips64el-unknown-linux-gnuabi64 | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
27+
; RUN: %if mips-registered-target %{ llc %s -o - -mtriple=mipsel-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
28+
; RUN: %if msp430-registered-target %{ llc %s -o - -mtriple=msp430-none-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
29+
; RUN: %if nvptx-registered-target %{ llc %s -o - -mtriple=nvptx64-nvidia-cuda | FileCheck %s --check-prefixes=NOCRASH %}
30+
; RUN: %if powerpc-registered-target %{ llc %s -o - -mtriple=powerpc-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
31+
; RUN: %if powerpc-registered-target %{ llc %s -o - -mtriple=powerpc64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
32+
; RUN: %if powerpc-registered-target %{ llc %s -o - -mtriple=powerpc64le-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
33+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
34+
; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
35+
; RUN: %if sparc-registered-target %{ llc %s -o - -mtriple=sparc-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
36+
; RUN: %if sparc-registered-target %{ llc %s -o - -mtriple=sparc64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
37+
; RUN: %if spirv-registered-target %{ llc %s -o - -mtriple=spirv-unknown-unknown | FileCheck %s --check-prefixes=NOCRASH %}
38+
; RUN: %if systemz-registered-target %{ llc %s -o - -mtriple=s390x-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
39+
; RUN: %if ve-registered-target %{ llc %s -o - -mtriple=ve-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
40+
; RUN: %if webassembly-registered-target %{ llc %s -o - -mtriple=wasm32-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
41+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=i686-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
42+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
43+
; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-NEG-ABS,CHECK-COPYSIGN,BAD-FMA %}
44+
; RUN: %if xcore-registered-target %{ llc %s -o - -mtriple=xcore-unknown-unknown | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,BAD-FMA %}
45+
; RUN: %if xtensa-registered-target %{ llc %s -o - -mtriple=xtensa-none-elf | FileCheck %s --check-prefixes=ALL,BAD-NEG-ABS,BAD-COPYSIGN,CHECK-FMA %}
46+
47+
; Note that arm64ec labels are quoted, hence the `{{"?}}:`.
48+
49+
; Codegen tests don't work the same for graphics targets. Add a dummy directive
50+
; for filecheck, just make sure we don't crash.
51+
; NOCRASH: {{.*}}
52+
53+
; fneg, fabs and copysign all need to not quieten signalling NaNs, so should not call any conversion functions which do.
54+
; These tests won't catch cases where the everything is done using native instructions instead of builtins.
55+
; See https://github.com/llvm/llvm-project/issues/104915
56+
57+
define void @test_fneg(ptr %p1, ptr %p2) #0 {
58+
; ALL-LABEL: test_fneg{{"?}}:
59+
; CHECK-NEG-ABS-NOT: __extend
60+
; CHECK-NEG-ABS-NOT: __trunc
61+
; CHECK-NEG-ABS-NOT: __gnu
62+
; CHECK-NEG-ABS-NOT: __aeabi
63+
; BAD-NEG-ABS: {{__extendhfsf2|__gnu_h2f_ieee|__aeabi_h2f}}
64+
%v = load half, ptr %p1
65+
%res = fneg half %v
66+
store half %res, ptr %p2
67+
ret void
68+
}
69+
70+
define void @test_fabs(ptr %p1, ptr %p2) {
71+
; ALL-LABEL: test_fabs{{"?}}:
72+
; CHECK-NEG-ABS-NOT: __extend
73+
; CHECK-NEG-ABS-NOT: __trunc
74+
; CHECK-NEG-ABS-NOT: __gnu
75+
; CHECK-NEG-ABS-NOT: __aeabi
76+
; BAD-NEG-ABS: {{__extendhfsf2|__gnu_h2f_ieee|__aeabi_h2f}}
77+
%a = load half, ptr %p1
78+
%r = call half @llvm.fabs.f16(half %a)
79+
store half %r, ptr %p2
80+
ret void
81+
}
82+
83+
define void @test_copysign(ptr %p1, ptr %p2, ptr %p3) {
84+
; ALL-LABEL: test_copysign{{"?}}:
85+
; CHECK-COPYSIGN-NOT: __extend
86+
; CHECK-COPYSIGN-NOT: __trunc
87+
; CHECK-COPYSIGN-NOT: __gnu
88+
; CHECK-COPYSIGN-NOT: __aeabi
89+
; BAD-COPYSIGN: {{__extendhfsf2|__gnu_h2f_ieee}}
90+
%a = load half, ptr %p1
91+
%b = load half, ptr %p2
92+
%r = call half @llvm.copysign.f16(half %a, half %b)
93+
store half %r, ptr %p3
94+
ret void
95+
}
96+
97+
; If promoting, fma must promote at least to f64 to avoid double rounding issues.
98+
; This checks for calls to f32 fmaf and truncating f32 to f16.
99+
; See https://github.com/llvm/llvm-project/issues/98389
100+
101+
define void @test_fma(ptr %p1, ptr %p2, ptr %p3, ptr %p4) {
102+
; ALL-LABEL: test_fma{{"?}}:
103+
; Allow fmaf16
104+
; CHECK-FMA-NOT: fmaf{{\b}}
105+
; CHECK-FMA-NOT: __truncsfhf2
106+
; CHECK-FMA-NOT: __gnu_f2h_ieee
107+
; CHECK-FMA-NOT: __aeabi_f2h
108+
; BAD-FMA: {{__truncsfhf2|__gnu_f2h_ieee|__aeabi_f2h|fmaf\b}}
109+
%a = load half, ptr %p1
110+
%b = load half, ptr %p2
111+
%c = load half, ptr %p3
112+
%r = call half @llvm.fma.f16(half %a, half %b, half %c)
113+
store half %r, ptr %p4
114+
ret void
115+
}

0 commit comments

Comments
 (0)