llvm-project/flang/test/Lower/fast-math-arithmetic.f90
Tom Eccles e7b6660243 [flang] Add -ffast-math and -Ofast
clang -cc1 accepts -Ofast. I did not add it to flang -fc1 because this
seems redundant because the compiler driver will always resolve -Ofast
into -O3 -ffast-math (I added a test for this).

-menable-infs is removed from the frontend-forwarding test because if
all of the fast-math component flags are present, these will be resolved
into the fast-math flag. Instead -menable-infs is tested in the
fast-math test.

Specifying -ffast-math to the compiler driver causes linker invocations
to include crtfastmath.o.

RFC: https://discourse.llvm.org/t/rfc-the-meaning-of-ofast/66554

Differential Revision: https://reviews.llvm.org/D138675
2022-12-09 19:55:58 +00:00

27 lines
1.9 KiB
Fortran

! RUN: %flang_fc1 -emit-fir -ffp-contract=fast %s -o - 2>&1 | FileCheck --check-prefixes=CONTRACT,ALL %s
! RUN: %flang_fc1 -emit-fir -menable-no-infs -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=NINF,ALL %s
! RUN: %flang_fc1 -emit-fir -menable-no-nans -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=NNAN,ALL %s
! RUN: %flang_fc1 -emit-fir -fapprox-func -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=AFN,ALL %s
! RUN: %flang_fc1 -emit-fir -fno-signed-zeros -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=NSZ,ALL %s
! RUN: %flang_fc1 -emit-fir -mreassociate -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=REASSOC,ALL %s
! RUN: %flang_fc1 -emit-fir -freciprocal-math -ffp-contract=off %s -o - 2>&1 | FileCheck --check-prefixes=ARCP,ALL %s
! RUN: %flang_fc1 -emit-fir -ffp-contract=fast -menable-no-infs -menable-no-nans -fapprox-func -fno-signed-zeros -mreassociate -freciprocal-math %s -o - 2>&1 | FileCheck --check-prefixes=FAST,ALL %s
! RUN: %flang_fc1 -emit-fir -ffast-math %s -o - 2>&1 | FileCheck --check-prefixes=FAST,ALL %s
! ALL-LABEL: func.func @_QPtest
subroutine test(x)
real x
! CONTRACT: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:contract]]> : f32
! NINF: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:ninf]]> : f32
! NNAN: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:nnan]]> : f32
! AFN: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:afn]]> : f32
! NSZ: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:nsz]]> : f32
! REASSOC: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:reassoc]]> : f32
! ARCP: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:arcp]]> : f32
! FAST: arith.mulf{{.*}}, {{.*}} fastmath<[[ATTRS:fast]]> : f32
! ALL: arith.divf{{.*}}, {{.*}} fastmath<[[ATTRS]]> : f32
! ALL: arith.addf{{.*}}, {{.*}} fastmath<[[ATTRS]]> : f32
! ALL: arith.subf{{.*}}, {{.*}} fastmath<[[ATTRS]]> : f32
x = x * x + x / x - x
end subroutine test