105 lines · plain
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-COPYSIGN,CHECK-FMA %}6; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,CHECK-FMA %}7; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=aarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,CHECK-FMA %}8; RUN: %if aarch64-registered-target %{ llc %s -o - -mtriple=arm64ec-pc-windows-msvc | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,CHECK-FMA %}9; RUN: %if amdgpu-registered-target %{ llc %s -o - -mtriple=amdgcn-amd-amdhsa | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,CHECK-FMA %}10; RUN: %if arc-registered-target %{ llc %s -o - -mtriple=arc-elf | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}11; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=arm-unknown-linux-gnueabi | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}12; RUN: %if arm-registered-target %{ llc %s -o - -mtriple=thumbv7em-none-eabi | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}13; RUN: %if avr-registered-target %{ llc %s -o - -mtriple=avr-none | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}14; FIXME: BPF has a compiler error15; RUN: %if csky-registered-target %{ llc %s -o - -mtriple=csky-unknown-linux-gnuabiv2 | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}16; FIXME: hard float csky crashes17; FIXME: directx has a compiler error18; FIXME: hexagon crashes19; RUN: %if lanai-registered-target %{ llc %s -o - -mtriple=lanai-unknown-unknown | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}20; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}21; RUN: %if loongarch-registered-target %{ llc %s -o - -mtriple=loongarch64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,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,CHECK-COPYSIGN,BAD-FMA %}23; RUN: %if m68k-registered-target %{ llc %s -o - -mtriple=m68k-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}24; FIXME: mips crashes25; RUN: %if msp430-registered-target %{ llc %s -o - -mtriple=msp430-none-elf | FileCheck %s --check-prefixes=ALL,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 crashes28; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv32-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}29; RUN: %if riscv-registered-target %{ llc %s -o - -mtriple=riscv64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}30; FIXME: sparc crashes31; FIXME: spirv crashes32; FIXME: s390x crashes33; FIXME: ve crashes34; FIXME: wasm crashes35; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=i686-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,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-COPYSIGN,BAD-FMA %}37; RUN: %if x86-registered-target %{ llc %s -o - -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}38; RUN: %if xcore-registered-target %{ llc %s -o - -mtriple=xcore-unknown-unknown | FileCheck %s --check-prefixes=ALL,CHECK-COPYSIGN,BAD-FMA %}39; RUN: %if xtensa-registered-target %{ llc %s -o - -mtriple=xtensa-none-elf | FileCheck %s --check-prefixes=ALL,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 directive44; 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 50define void @test_fneg(ptr %p1, ptr %p2) #0 {51; ALL-LABEL: test_fneg{{"?}}:52; ALL-NEG-NOT: __extend53; ALL-NEG-NOT: __trunc54; ALL-NEG-NOT: __gnu55; ALL-NEG-NOT: __aeabi56 %v = load bfloat, ptr %p157 %res = fneg bfloat %v58 store bfloat %res, ptr %p259 ret void60}61 62define void @test_fabs(ptr %p1, ptr %p2) {63; ALL-LABEL: test_fabs{{"?}}:64; ALL-ABS-NOT: __extend65; ALL-ABS-NOT: __trunc66; ALL-ABS-NOT: __gnu67; ALL-ABS-NOT: __aeabi68 %a = load bfloat, ptr %p169 %r = call bfloat @llvm.fabs.f16(bfloat %a)70 store bfloat %r, ptr %p271 ret void72}73 74define void @test_copysign(ptr %p1, ptr %p2, ptr %p3) {75; ALL-LABEL: test_copysign{{"?}}:76; CHECK-COPYSIGN-NOT: __extend77; CHECK-COPYSIGN-NOT: __trunc78; CHECK-COPYSIGN-NOT: __gnu79; CHECK-COPYSIGN-NOT: __aeabi80; BAD-COPYSIGN: __truncsfbf281 %a = load bfloat, ptr %p182 %b = load bfloat, ptr %p283 %r = call bfloat @llvm.copysign.f16(bfloat %a, bfloat %b)84 store bfloat %r, ptr %p385 ret void86}87 88; There is no floating-point type LLVM supports that is large enough to promote bfloat FMA to89; without causing double rounding issues. This checks for libcalls to f32/f64 fma and truncating90; f32/f64 to bf16. See https://github.com/llvm/llvm-project/issues/13153191 92define void @test_fma(ptr %p1, ptr %p2, ptr %p3, ptr %p4) {93; ALL-LABEL: test_fma{{"?}}:94; CHECK-FMA-NOT: {{\bfmaf?\b}}95; CHECK-FMA-NOT: __truncsfbf296; CHECK-FMA-NOT: __truncdfbf297; BAD-FMA: {{__truncsfbf2|\bfmaf?\b}}98 %a = load bfloat, ptr %p199 %b = load bfloat, ptr %p2100 %c = load bfloat, ptr %p3101 %r = call bfloat @llvm.fma.f16(bfloat %a, bfloat %b, bfloat %c)102 store bfloat %r, ptr %p4103 ret void104}105