diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -994,37 +994,15 @@ // Math runtime description and matching utility //===----------------------------------------------------------------------===// -/// Command line option to control how math operations are lowered -/// into MLIR. -/// Going forward, most of the math operations have to be lowered -/// to some MLIR dialect operations or libm calls, if the corresponding -/// MLIR operation is not available or not reasonable to create -/// (e.g. there are no known optimization opportunities for the math -/// operation in MLIR). -/// -/// In general, exposing MLIR operations early can potentially enable more -/// MLIR optimizations. -llvm::cl::opt lowerEarlyToLibCall( - "lower-math-early", - llvm::cl::desc("Controls when to lower Math intrinsics to library calls"), - llvm::cl::init(true)); - /// Command line option to modify math runtime behavior used to implement /// intrinsics. This option applies both to early and late math-lowering modes. -enum MathRuntimeVersion { - fastVersion, - relaxedVersion, - preciseVersion, - llvmOnly -}; +enum MathRuntimeVersion { fastVersion, relaxedVersion, preciseVersion }; llvm::cl::opt mathRuntimeVersion( "math-runtime", llvm::cl::desc("Select math operations' runtime behavior:"), llvm::cl::values( clEnumValN(fastVersion, "fast", "use fast runtime behavior"), clEnumValN(relaxedVersion, "relaxed", "use relaxed runtime behavior"), - clEnumValN(preciseVersion, "precise", "use precise runtime behavior"), - clEnumValN(llvmOnly, "llvm", - "only use LLVM intrinsics (may be incomplete)")), + clEnumValN(preciseVersion, "precise", "use precise runtime behavior")), llvm::cl::init(fastVersion)); struct RuntimeFunction { @@ -1271,59 +1249,6 @@ {"tanh", "tanh", genF64F64FuncType, genMathOp}, }; -// Note: These are also defined as operations in LLVM dialect. See if this -// can be use and has advantages. -// TODO: remove this table, since the late math lowering should -// replace it and generate proper MLIR operations rather -// than llvm intrinsic calls, which still look like generic -// calls to MLIR and do not enable many optimizations. -// When late math lowering is able to handle all math operations -// described in pgmath.h.inc and in the table below, we can -// switch to it by default. -static constexpr RuntimeFunction llvmIntrinsics[] = { - {"abs", "llvm.fabs.f32", genF32F32FuncType}, - {"abs", "llvm.fabs.f64", genF64F64FuncType}, - {"abs", "llvm.fabs.f128", genF128F128FuncType}, - {"aint", "llvm.trunc.f32", genF32F32FuncType}, - {"aint", "llvm.trunc.f64", genF64F64FuncType}, - {"anint", "llvm.round.f32", genF32F32FuncType}, - {"anint", "llvm.round.f64", genF64F64FuncType}, - {"atan", "atanf", genF32F32FuncType}, - {"atan", "atan", genF64F64FuncType}, - // ceil is used for CEILING but is different, it returns a real. - {"ceil", "llvm.ceil.f32", genF32F32FuncType}, - {"ceil", "llvm.ceil.f64", genF64F64FuncType}, - {"cos", "llvm.cos.f32", genF32F32FuncType}, - {"cos", "llvm.cos.f64", genF64F64FuncType}, - {"cosh", "coshf", genF32F32FuncType}, - {"cosh", "cosh", genF64F64FuncType}, - {"exp", "llvm.exp.f32", genF32F32FuncType}, - {"exp", "llvm.exp.f64", genF64F64FuncType}, - // llvm.floor is used for FLOOR, but returns real. - {"floor", "llvm.floor.f32", genF32F32FuncType}, - {"floor", "llvm.floor.f64", genF64F64FuncType}, - {"log", "llvm.log.f32", genF32F32FuncType}, - {"log", "llvm.log.f64", genF64F64FuncType}, - {"log10", "llvm.log10.f32", genF32F32FuncType}, - {"log10", "llvm.log10.f64", genF64F64FuncType}, - {"nint", "llvm.lround.i64.f64", genIntF64FuncType<64>}, - {"nint", "llvm.lround.i64.f32", genIntF32FuncType<64>}, - {"nint", "llvm.lround.i32.f64", genIntF64FuncType<32>}, - {"nint", "llvm.lround.i32.f32", genIntF32FuncType<32>}, - {"pow", "llvm.pow.f32", genF32F32F32FuncType}, - {"pow", "llvm.pow.f64", genF64F64F64FuncType}, - {"sign", "llvm.copysign.f32", genF32F32F32FuncType}, - {"sign", "llvm.copysign.f64", genF64F64F64FuncType}, - {"sign", "llvm.copysign.f80", genF80F80F80FuncType}, - {"sign", "llvm.copysign.f128", genF128F128F128FuncType}, - {"sin", "llvm.sin.f32", genF32F32FuncType}, - {"sin", "llvm.sin.f64", genF64F64FuncType}, - {"sinh", "sinhf", genF32F32FuncType}, - {"sinh", "sinh", genF64F64FuncType}, - {"sqrt", "llvm.sqrt.f32", genF32F32FuncType}, - {"sqrt", "llvm.sqrt.f64", genF64F64FuncType}, -}; - // This helper class computes a "distance" between two function types. // The distance measures how many narrowing conversions of actual arguments // and result of "from" must be made in order to use "to" instead of "from". @@ -1592,35 +1517,19 @@ static constexpr RtMap pgmathP(pgmathPrecise); static_assert(pgmathP.Verify() && "map must be sorted"); - if (mathRuntimeVersion == fastVersion) { + if (mathRuntimeVersion == fastVersion) match = searchFunctionInLibrary(loc, builder, pgmathF, name, funcType, &bestNearMatch, bestMatchDistance); - } else if (mathRuntimeVersion == relaxedVersion) { + else if (mathRuntimeVersion == relaxedVersion) match = searchFunctionInLibrary(loc, builder, pgmathR, name, funcType, &bestNearMatch, bestMatchDistance); - } else if (mathRuntimeVersion == preciseVersion) { + else if (mathRuntimeVersion == preciseVersion) match = searchFunctionInLibrary(loc, builder, pgmathP, name, funcType, &bestNearMatch, bestMatchDistance); - } else { - assert(mathRuntimeVersion == llvmOnly && "unknown math runtime"); - } - if (match) - return match; - - // Go through llvm intrinsics if not exact match in libpgmath or if - // mathRuntimeVersion == llvmOnly - static constexpr RtMap llvmIntr(llvmIntrinsics); - static_assert(llvmIntr.Verify() && "map must be sorted"); - if (mlir::func::FuncOp exactMatch = - searchFunctionInLibrary(loc, builder, llvmIntr, name, funcType, - &bestNearMatch, bestMatchDistance)) - return exactMatch; - - if (bestNearMatch != nullptr) { - checkPrecisionLoss(name, funcType, bestMatchDistance, loc); - return getFuncOp(loc, builder, *bestNearMatch); - } - return {}; + else + llvm_unreachable("unsupported mathRuntimeVersion"); + + return match; } /// Helpers to get function type from arguments and result type. @@ -2010,24 +1919,37 @@ mlir::func::FuncOp funcOp; mlir::FunctionType actualFuncType; const MathOperation *mathOp = nullptr; - if (!lowerEarlyToLibCall) { - // Look for a dedicated math operation generator, which - // normally produces a single MLIR operation implementing - // the math operation. - // If not found fall back to a runtime function lookup. - const MathOperation *bestNearMatch = nullptr; - FunctionDistance bestMatchDistance; - mathOp = searchMathOperation(builder, name, soughtFuncType, &bestNearMatch, - bestMatchDistance); - if (!mathOp && bestNearMatch) { - // Use the best near match, optionally issuing an error, - // if types conversions cause precision loss. + + // Look for a dedicated math operation generator, which + // normally produces a single MLIR operation implementing + // the math operation. + // If not found fall back to a runtime function lookup. + const MathOperation *bestNearMatch = nullptr; + FunctionDistance bestMatchDistance; + mathOp = searchMathOperation(builder, name, soughtFuncType, &bestNearMatch, + bestMatchDistance); + if (!mathOp && bestNearMatch) { + // Use the best near match, optionally issuing an error, + // if types conversions cause precision loss. + bool useBestNearMatch = true; + // TODO: temporary workaround to avoid using math::PowFOp + // for pow(fp, i64) case and fall back to pgmath runtime. + // When proper Math dialect operations are available + // and added into mathOperations table, this can be removed. + // This is WIP in D129812. + if (name == "pow" && soughtFuncType.getInput(0).isa()) + if (auto exponentTy = + soughtFuncType.getInput(1).dyn_cast()) + useBestNearMatch = exponentTy.getWidth() != 64; + + if (useBestNearMatch) { checkPrecisionLoss(name, soughtFuncType, bestMatchDistance, loc); mathOp = bestNearMatch; } - if (mathOp) - actualFuncType = mathOp->typeGenerator(builder.getContext()); } + if (mathOp) + actualFuncType = mathOp->typeGenerator(builder.getContext()); + if (!mathOp) if ((funcOp = getRuntimeFunction(loc, builder, name, soughtFuncType))) actualFuncType = funcOp.getFunctionType(); @@ -4529,7 +4451,7 @@ mlir::Value x, mlir::Value y) { // TODO: since there is no libm version of pow with integer exponent, // we have to provide an alternative implementation for - // "precise/strict" FP mode and (!lowerEarlyToLibCall). + // "precise/strict" FP mode. // One option is to generate internal function with inlined // implementation and mark it 'strictfp'. // Another option is to implement it in Fortran runtime library diff --git a/flang/test/Intrinsics/late-math-codegen.fir b/flang/test/Intrinsics/math-codegen.fir rename from flang/test/Intrinsics/late-math-codegen.fir rename to flang/test/Intrinsics/math-codegen.fir diff --git a/flang/test/Lower/Intrinsics/abs.f90 b/flang/test/Lower/Intrinsics/abs.f90 --- a/flang/test/Lower/Intrinsics/abs.f90 +++ b/flang/test/Lower/Intrinsics/abs.f90 @@ -36,7 +36,7 @@ subroutine abs_testh(a, b) ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref ! CHECK: %[[VAL_2_1:.*]] = fir.convert %[[VAL_2]] : (f16) -> f32 -! CHECK: %[[VAL_3:.*]] = fir.call @llvm.fabs.f32(%[[VAL_2_1]]) : (f32) -> f32 +! CHECK: %[[VAL_3:.*]] = math.abs %[[VAL_2_1]] : f32 ! CHECK: %[[VAL_3_1:.*]] = fir.convert %[[VAL_3]] : (f32) -> f16 ! CHECK: fir.store %[[VAL_3_1]] to %[[VAL_1]] : !fir.ref ! CHECK: return @@ -49,7 +49,7 @@ subroutine abs_testb(a, b) ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref ! CHECK: %[[VAL_2_1:.*]] = fir.convert %[[VAL_2]] : (bf16) -> f32 -! CHECK: %[[VAL_3:.*]] = fir.call @llvm.fabs.f32(%[[VAL_2_1]]) : (f32) -> f32 +! CHECK: %[[VAL_3:.*]] = math.abs %[[VAL_2_1]] : f32 ! CHECK: %[[VAL_3_1:.*]] = fir.convert %[[VAL_3]] : (f32) -> bf16 ! CHECK: fir.store %[[VAL_3_1]] to %[[VAL_1]] : !fir.ref ! CHECK: return @@ -61,7 +61,7 @@ ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref{{.*}}, %[[VAL_1:.*]]: !fir.ref{{.*}}) { subroutine abs_testr(a, b) ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_3:.*]] = fir.call @llvm.fabs.f32(%[[VAL_2]]) : (f32) -> f32 +! CHECK: %[[VAL_3:.*]] = math.abs %[[VAL_2]] : f32 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref ! CHECK: return real :: a, b @@ -72,7 +72,7 @@ ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref{{.*}}, %[[VAL_1:.*]]: !fir.ref{{.*}}) { subroutine abs_testd(a, b) ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_3:.*]] = fir.call @llvm.fabs.f64(%[[VAL_2]]) : (f64) -> f64 +! CHECK: %[[VAL_3:.*]] = math.abs %[[VAL_2]] : f64 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref ! CHECK: return real(kind=8) :: a, b @@ -83,7 +83,7 @@ ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref{{.*}}, %[[VAL_1:.*]]: !fir.ref{{.*}}) { subroutine abs_testr16(a, b) ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_3:.*]] = fir.call @llvm.fabs.f128(%[[VAL_2]]) : (f128) -> f128 +! CHECK: %[[VAL_3:.*]] = math.abs %[[VAL_2]] : f128 ! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref ! CHECK: return real(kind=16) :: a, b @@ -96,7 +96,7 @@ ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref> ! CHECK: %[[VAL_3:.*]] = fir.extract_value %[[VAL_2]], [0 : index] : (!fir.complex<4>) -> f32 ! CHECK: %[[VAL_4:.*]] = fir.extract_value %[[VAL_2]], [1 : index] : (!fir.complex<4>) -> f32 -! CHECK: %[[VAL_5:.*]] = fir.call @__mth_i_hypot(%[[VAL_3]], %[[VAL_4]]) : (f32, f32) -> f32 +! CHECK: %[[VAL_5:.*]] = fir.call @hypotf(%[[VAL_3]], %[[VAL_4]]) : (f32, f32) -> f32 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_1]] : !fir.ref ! CHECK: return complex :: a @@ -110,7 +110,7 @@ ! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref> ! CHECK: %[[VAL_3:.*]] = fir.extract_value %[[VAL_2]], [0 : index] : (!fir.complex<8>) -> f64 ! CHECK: %[[VAL_4:.*]] = fir.extract_value %[[VAL_2]], [1 : index] : (!fir.complex<8>) -> f64 -! CHECK: %[[VAL_5:.*]] = fir.call @__mth_i_dhypot(%[[VAL_3]], %[[VAL_4]]) : (f64, f64) -> f64 +! CHECK: %[[VAL_5:.*]] = fir.call @hypot(%[[VAL_3]], %[[VAL_4]]) : (f64, f64) -> f64 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_1]] : !fir.ref ! CHECK: return complex(kind=8) :: a diff --git a/flang/test/Lower/Intrinsics/anint.f90 b/flang/test/Lower/Intrinsics/anint.f90 --- a/flang/test/Lower/Intrinsics/anint.f90 +++ b/flang/test/Lower/Intrinsics/anint.f90 @@ -3,7 +3,7 @@ ! CHECK-LABEL: anint_test subroutine anint_test(a, b) real :: a, b - ! CHECK: fir.call @llvm.round.f32 + ! CHECK: "llvm.intr.round" b = anint(a) end subroutine - \ No newline at end of file + diff --git a/flang/test/Lower/Intrinsics/ceiling.f90 b/flang/test/Lower/Intrinsics/ceiling.f90 --- a/flang/test/Lower/Intrinsics/ceiling.f90 +++ b/flang/test/Lower/Intrinsics/ceiling.f90 @@ -5,7 +5,7 @@ integer :: i real :: a i = ceiling(a) - ! CHECK: %[[f:.*]] = fir.call @llvm.ceil.f32 + ! CHECK: %[[f:.*]] = math.ceil %{{.*}} : f32 ! CHECK: fir.convert %[[f]] : (f32) -> i32 end subroutine ! CHECK-LABEL: ceiling_test2 @@ -13,8 +13,8 @@ integer(8) :: i real :: a i = ceiling(a, 8) - ! CHECK: %[[f:.*]] = fir.call @llvm.ceil.f32 + ! CHECK: %[[f:.*]] = math.ceil %{{.*}} : f32 ! CHECK: fir.convert %[[f]] : (f32) -> i64 end subroutine - \ No newline at end of file + diff --git a/flang/test/Lower/Intrinsics/exp.f90 b/flang/test/Lower/Intrinsics/exp.f90 --- a/flang/test/Lower/Intrinsics/exp.f90 +++ b/flang/test/Lower/Intrinsics/exp.f90 @@ -43,12 +43,12 @@ ! CHECK-LABEL: private @fir.exp.f32.f32 ! CHECK-SAME: (%[[ARG32_OUTLINE:.*]]: f32) -> f32 -! CHECK: %[[RESULT32_OUTLINE:.*]] = fir.call @__fs_exp_1(%[[ARG32_OUTLINE]]) : (f32) -> f32 +! CHECK: %[[RESULT32_OUTLINE:.*]] = math.exp %[[ARG32_OUTLINE]] : f32 ! CHECK: return %[[RESULT32_OUTLINE]] : f32 ! CHECK-LABEL: private @fir.exp.f64.f64 ! CHECK-SAME: (%[[ARG64_OUTLINE:.*]]: f64) -> f64 -! CHECK: %[[RESULT64_OUTLINE:.*]] = fir.call @__fd_exp_1(%[[ARG64_OUTLINE]]) : (f64) -> f64 +! CHECK: %[[RESULT64_OUTLINE:.*]] = math.exp %[[ARG64_OUTLINE]] : f64 ! CHECK: return %[[RESULT64_OUTLINE]] : f64 ! CHECK-LABEL: private @fir.exp.z4.z4 diff --git a/flang/test/Lower/Intrinsics/floor.f90 b/flang/test/Lower/Intrinsics/floor.f90 --- a/flang/test/Lower/Intrinsics/floor.f90 +++ b/flang/test/Lower/Intrinsics/floor.f90 @@ -5,7 +5,7 @@ integer :: i real :: a i = floor(a) - ! CHECK: %[[f:.*]] = fir.call @llvm.floor.f32 + ! CHECK: %[[f:.*]] = math.floor %{{.*}} : f32 ! CHECK: fir.convert %[[f]] : (f32) -> i32 end subroutine ! CHECK-LABEL: floor_test2 @@ -13,7 +13,7 @@ integer(8) :: i real :: a i = floor(a, 8) - ! CHECK: %[[f:.*]] = fir.call @llvm.floor.f32 + ! CHECK: %[[f:.*]] = math.floor %{{.*}} : f32 ! CHECK: fir.convert %[[f]] : (f32) -> i64 end subroutine - \ No newline at end of file + diff --git a/flang/test/Lower/Intrinsics/log.f90 b/flang/test/Lower/Intrinsics/log.f90 --- a/flang/test/Lower/Intrinsics/log.f90 +++ b/flang/test/Lower/Intrinsics/log.f90 @@ -63,12 +63,12 @@ ! CHECK-LABEL: private @fir.log.f32.f32 ! CHECK-SAME: (%[[ARG32_OUTLINE:.*]]: f32) -> f32 -! CHECK: %[[RESULT32_OUTLINE:.*]] = fir.call @__fs_log_1(%[[ARG32_OUTLINE]]) : (f32) -> f32 +! CHECK: %[[RESULT32_OUTLINE:.*]] = math.log %[[ARG32_OUTLINE]] : f32 ! CHECK: return %[[RESULT32_OUTLINE]] : f32 ! CHECK-LABEL: private @fir.log.f64.f64 ! CHECK-SAME: (%[[ARG64_OUTLINE:.*]]: f64) -> f64 -! CHECK: %[[RESULT64_OUTLINE:.*]] = fir.call @__fd_log_1(%[[ARG64_OUTLINE]]) : (f64) -> f64 +! CHECK: %[[RESULT64_OUTLINE:.*]] = math.log %[[ARG64_OUTLINE]] : f64 ! CHECK: return %[[RESULT64_OUTLINE]] : f64 ! CHECK-LABEL: private @fir.log.z4.z4 @@ -83,10 +83,10 @@ ! CHECK-LABEL: private @fir.log10.f32.f32 ! CHECK-SAME: (%[[ARG32_OUTLINE:.*]]: f32) -> f32 -! CHECK: %[[RESULT32_OUTLINE:.*]] = fir.call @__fs_log10_1(%[[ARG32_OUTLINE]]) : (f32) -> f32 +! CHECK: %[[RESULT32_OUTLINE:.*]] = math.log10 %[[ARG32_OUTLINE]] : f32 ! CHECK: return %[[RESULT32_OUTLINE]] : f32 ! CHECK-LABEL: private @fir.log10.f64.f64 ! CHECK-SAME: (%[[ARG64_OUTLINE:.*]]: f64) -> f64 -! CHECK: %[[RESULT64_OUTLINE:.*]] = fir.call @__fd_log10_1(%[[ARG64_OUTLINE]]) : (f64) -> f64 +! CHECK: %[[RESULT64_OUTLINE:.*]] = math.log10 %[[ARG64_OUTLINE]] : f64 ! CHECK: return %[[RESULT64_OUTLINE]] : f64 diff --git a/flang/test/Lower/Intrinsics/math-runtime-options.f90 b/flang/test/Lower/Intrinsics/math-runtime-options.f90 --- a/flang/test/Lower/Intrinsics/math-runtime-options.f90 +++ b/flang/test/Lower/Intrinsics/math-runtime-options.f90 @@ -4,8 +4,6 @@ ! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="FIR,RELAXED" ! RUN: bbc -emit-fir --math-runtime=precise -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="FIR,PRECISE" ! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="FIR,PRECISE" -! RUN: bbc -emit-fir --math-runtime=llvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="FIR,LLVM" -! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=llvm -mllvm -outline-intrinsics %s -o - | FileCheck %s --check-prefixes="FIR,LLVM" ! CHECK-LABEL: cos_testr subroutine cos_testr(a, b) @@ -22,12 +20,10 @@ end subroutine ! FIR: @fir.cos.f32.f32(%arg0: f32) -> f32 attributes -! FAST: fir.call @__fs_cos_1(%arg0) : (f32) -> f32 -! RELAXED: fir.call @__rs_cos_1(%arg0) : (f32) -> f32 -! PRECISE: fir.call @__ps_cos_1(%arg0) : (f32) -> f32 -! LLVM: fir.call @llvm.cos.f32(%arg0) : (f32) -> f32 +! FAST: math.cos %arg0 : f32 +! RELAXED: math.cos %arg0 : f32 +! PRECISE: fir.call @cosf(%arg0) : (f32) -> f32 ! FIR: @fir.cos.f64.f64(%arg0: f64) -> f64 -! FAST: fir.call @__fd_cos_1(%arg0) : (f64) -> f64 -! RELAXED: fir.call @__rd_cos_1(%arg0) : (f64) -> f64 -! PRECISE: fir.call @__pd_cos_1(%arg0) : (f64) -> f64 -! LLVM: fir.call @llvm.cos.f64(%arg0) : (f64) -> f64 +! FAST: math.cos %arg0 : f64 +! RELAXED: math.cos %arg0 : f64 +! PRECISE: fir.call @cos(%arg0) : (f64) -> f64 diff --git a/flang/test/Lower/Intrinsics/sign.f90 b/flang/test/Lower/Intrinsics/sign.f90 --- a/flang/test/Lower/Intrinsics/sign.f90 +++ b/flang/test/Lower/Intrinsics/sign.f90 @@ -16,7 +16,7 @@ subroutine sign_testr(a, b, c) real a, b, c ! CHECK-NOT: fir.call @{{.*}}fabs - ! CHECK: fir.call @{{.*}}copysign{{.*}} : (f32, f32) -> f32 + ! CHECK: math.copysign{{.*}} : f32 c = sign(a, b) end subroutine @@ -24,6 +24,6 @@ subroutine sign_testr2(a, b, c) real(KIND=16) a, b, c ! CHECK-NOT: fir.call @{{.*}}fabs - ! CHECK: fir.call @{{.*}}copysign{{.*}} : (f128, f128) -> f128 + ! CHECK: math.copysign{{.*}} : f128 c = sign(a, b) end subroutine diff --git a/flang/test/Lower/array-elemental-calls-2.f90 b/flang/test/Lower/array-elemental-calls-2.f90 --- a/flang/test/Lower/array-elemental-calls-2.f90 +++ b/flang/test/Lower/array-elemental-calls-2.f90 @@ -135,7 +135,7 @@ ! CHECK: fir.do_loop ! CHECK: %[[VAL_25:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64 ! CHECK: %[[VAL_26:.*]] = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<10xf64>, index) -> f64 -! CHECK: %[[VAL_27:.*]] = fir.call @__fd_pow_1(%[[VAL_25]], %[[VAL_26]]) : (f64, f64) -> f64 +! CHECK: %[[VAL_27:.*]] = math.powf %[[VAL_25]], %[[VAL_26]] : f64 ! CHECK: fir.store %[[VAL_27]] to %[[VAL_0]] : !fir.ref ! CHECK: %[[VAL_28:.*]] = fir.call @_QPelem_func_real(%[[VAL_0]]) : (!fir.ref) -> i32 end subroutine diff --git a/flang/test/Lower/array-expression.f90 b/flang/test/Lower/array-expression.f90 --- a/flang/test/Lower/array-expression.f90 +++ b/flang/test/Lower/array-expression.f90 @@ -471,7 +471,7 @@ real :: a(100), b(100) ! CHECK: %[[loop:.*]] = fir.do_loop %[[i:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[bth:.*]] = %[[barr]]) -> (!fir.array<100xf32>) { ! CHECK: %[[val:.*]] = fir.array_fetch %[[aarr]], %[[i]] : (!fir.array<100xf32>, index) -> f32 - ! CHECK: %[[fres:.*]] = fir.call @llvm.fabs.f32(%[[val]]) : (f32) -> f32 + ! CHECK: %[[fres:.*]] = math.abs %[[val]] : f32 ! CHECK: %[[res:.*]] = fir.array_update %[[bth]], %[[fres]], %[[i]] : (!fir.array<100xf32>, f32, index) -> !fir.array<100xf32> ! CHECK: fir.result %[[res]] : !fir.array<100xf32> ! CHECK: fir.array_merge_store %[[barr]], %[[loop]] to %[[b]] diff --git a/flang/test/Lower/dummy-procedure.f90 b/flang/test/Lower/dummy-procedure.f90 --- a/flang/test/Lower/dummy-procedure.f90 +++ b/flang/test/Lower/dummy-procedure.f90 @@ -161,7 +161,7 @@ ! CHECK-SAME: %[[x:.*]]: !fir.ref, %[[y:.*]]: !fir.ref) -> f32 ! CHECK-DAG: %[[xload:.*]] = fir.load %[[x]] : !fir.ref ! CHECK-DAG: %[[yload:.*]] = fir.load %[[y]] : !fir.ref - ! CHECK: %[[atan2:.*]] = fir.call @__fs_atan2_1(%[[xload]], %[[yload]]) : (f32, f32) -> f32 + ! CHECK: %[[atan2:.*]] = math.atan2 %[[xload]], %[[yload]] : f32 ! CHECK: return %[[atan2]] : f32 !CHECK-LABEL: func private @fir.aimag.f32.ref_z4(%arg0: !fir.ref>) diff --git a/flang/test/Lower/late-math-lowering.f90 b/flang/test/Lower/late-math-lowering.f90 deleted file mode 100644 --- a/flang/test/Lower/late-math-lowering.f90 +++ /dev/null @@ -1,602 +0,0 @@ -! RUN: split-file %s %t - -//--- abs.f90 -! RUN: bbc -emit-fir %t/abs.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/abs.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/abs.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/abs.f90 -! RUN: bbc -emit-fir %t/abs.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/abs.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/abs.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/abs.f90 -! RUN: bbc -emit-fir %t/abs.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/abs.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/abs.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/abs.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = abs(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @fabsf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = abs(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @fabs({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -function test_real16(x) - real(16) :: x, test_real16 - test_real16 = abs(x) -end function -! ALL-LABEL: @_QPtest_real16 -! FAST: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f128 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f128 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.fabs.f128({{%[A-Za-z0-9._]+}}) : (f128) -> f128 - -function test_complex4(c) - complex(4) :: c, test_complex4 - test_complex4 = abs(c) -end function - -! ALL-LABEL: @_QPtest_complex4 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @hypotf({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 - -function test_complex8(c) - complex(8) :: c, test_complex8 - test_complex8 = abs(c) -end function - -! ALL-LABEL: @_QPtest_complex8 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @hypot({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 - -//--- aint.f90 -! RUN: bbc -emit-fir %t/aint.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL %t/aint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/aint.f90 -o - | FileCheck --check-prefixes=ALL %t/aint.f90 -! RUN: bbc -emit-fir %t/aint.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/aint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/aint.f90 -o - | FileCheck --check-prefixes=ALL %t/aint.f90 -! RUN: bbc -emit-fir %t/aint.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL %t/aint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/aint.f90 -o - | FileCheck --check-prefixes=ALL %t/aint.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = aint(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.trunc.f32({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = aint(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.trunc.f64({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- anint.f90 -! RUN: bbc -emit-fir %t/anint.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/anint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/anint.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/anint.f90 -! RUN: bbc -emit-fir %t/anint.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/anint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/anint.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/anint.f90 -! RUN: bbc -emit-fir %t/anint.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/anint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/anint.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/anint.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = anint(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f32) -> f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f32) -> f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f32({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = anint(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f64) -> f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f64) -> f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f64({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- atan.f90 -! RUN: bbc -emit-fir %t/atan.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/atan.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/atan.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/atan.f90 -! RUN: bbc -emit-fir %t/atan.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/atan.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/atan.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/atan.f90 -! RUN: bbc -emit-fir %t/atan.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/atan.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/atan.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/atan.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = atan(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atanf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = atan(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atan({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- atan2.f90 -! RUN: bbc -emit-fir %t/atan2.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/atan2.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/atan2.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/atan2.f90 -! RUN: bbc -emit-fir %t/atan2.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/atan2.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/atan2.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/atan2.f90 -! RUN: bbc -emit-fir %t/atan2.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/atan2.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/atan2.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/atan2.f90 - -function test_real4(x, y) - real :: x, y, test_real4 - test_real4 = atan2(x, y) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atan2f({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 - -function test_real8(x, y) - real(8) :: x, y, test_real8 - test_real8 = atan2(x, y) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atan2({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 - -//--- ceiling.f90 -! RUN: bbc -emit-fir %t/ceiling.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/ceiling.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/ceiling.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/ceiling.f90 -! RUN: bbc -emit-fir %t/ceiling.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/ceiling.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/ceiling.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/ceiling.f90 -! RUN: bbc -emit-fir %t/ceiling.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/ceiling.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/ceiling.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/ceiling.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = ceiling(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @ceilf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = ceiling(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @ceil({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- cos.f90 -! RUN: bbc -emit-fir %t/cos.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/cos.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/cos.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/cos.f90 -! RUN: bbc -emit-fir %t/cos.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/cos.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/cos.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/cos.f90 -! RUN: bbc -emit-fir %t/cos.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/cos.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/cos.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/cos.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = cos(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @cosf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = cos(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @cos({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- cosh.f90 -! RUN: bbc -emit-fir %t/cosh.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL %t/cosh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/cosh.f90 -o - | FileCheck --check-prefixes=ALL %t/cosh.f90 -! RUN: bbc -emit-fir %t/cosh.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/cosh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/cosh.f90 -o - | FileCheck --check-prefixes=ALL %t/cosh.f90 -! RUN: bbc -emit-fir %t/cosh.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL %t/cosh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/cosh.f90 -o - | FileCheck --check-prefixes=ALL %t/cosh.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = cosh(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @coshf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = cosh(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @cosh({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- erf.f90 -! RUN: bbc -emit-fir %t/erf.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/erf.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/erf.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/erf.f90 -! RUN: bbc -emit-fir %t/erf.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/erf.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/erf.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/erf.f90 -! RUN: bbc -emit-fir %t/erf.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/erf.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/erf.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/erf.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = erf(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erff({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = erf(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erf({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- exp.f90 -! RUN: bbc -emit-fir %t/exp.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/exp.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/exp.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/exp.f90 -! RUN: bbc -emit-fir %t/exp.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/exp.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/exp.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/exp.f90 -! RUN: bbc -emit-fir %t/exp.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/exp.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/exp.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/exp.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = exp(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @expf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = exp(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @exp({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- floor.f90 -! RUN: bbc -emit-fir %t/floor.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/floor.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/floor.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/floor.f90 -! RUN: bbc -emit-fir %t/floor.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/floor.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/floor.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/floor.f90 -! RUN: bbc -emit-fir %t/floor.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/floor.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/floor.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/floor.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = floor(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @floorf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = floor(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @floor({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- log.f90 -! RUN: bbc -emit-fir %t/log.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/log.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/log.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/log.f90 -! RUN: bbc -emit-fir %t/log.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/log.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/log.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/log.f90 -! RUN: bbc -emit-fir %t/log.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/log.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/log.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/log.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = log(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @logf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = log(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @log({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- log10.f90 -! RUN: bbc -emit-fir %t/log10.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/log10.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/log10.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/log10.f90 -! RUN: bbc -emit-fir %t/log10.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/log10.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/log10.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/log10.f90 -! RUN: bbc -emit-fir %t/log10.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/log10.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/log10.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/log10.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = log10(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @log10f({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = log10(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @log10({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- nint.f90 -! RUN: bbc -emit-fir %t/nint.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL %t/nint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/nint.f90 -o - | FileCheck --check-prefixes=ALL %t/nint.f90 -! RUN: bbc -emit-fir %t/nint.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/nint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/nint.f90 -o - | FileCheck --check-prefixes=ALL %t/nint.f90 -! RUN: bbc -emit-fir %t/nint.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL %t/nint.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/nint.f90 -o - | FileCheck --check-prefixes=ALL %t/nint.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = nint(x, 4) + nint(x, 8) -end function - -! ALL-LABEL: @_QPtest_real4 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i32.f32({{%[A-Za-z0-9._]+}}) : (f32) -> i32 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i64.f32({{%[A-Za-z0-9._]+}}) : (f32) -> i64 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = nint(x, 4) + nint(x, 8) -end function - -! ALL-LABEL: @_QPtest_real8 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i32.f64({{%[A-Za-z0-9._]+}}) : (f64) -> i32 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i64.f64({{%[A-Za-z0-9._]+}}) : (f64) -> i64 - -//--- exponentiation.f90 -! RUN: bbc -emit-fir %t/exponentiation.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/exponentiation.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/exponentiation.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/exponentiation.f90 -! RUN: bbc -emit-fir %t/exponentiation.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/exponentiation.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/exponentiation.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/exponentiation.f90 -! RUN: bbc -emit-fir %t/exponentiation.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/exponentiation.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/exponentiation.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/exponentiation.f90 - -function test_real4(x, y, s, i) - real :: x, y, test_real4 - integer(2) :: s - integer(4) :: i - test_real4 = x ** s + x ** y + x ** i -end function - -! ALL-LABEL: @_QPtest_real4 -! ALL: [[STOI:%[A-Za-z0-9._]+]] = fir.convert {{%[A-Za-z0-9._]+}} : (i16) -> i32 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f32.i32({{%[A-Za-z0-9._]+}}, [[STOI]]) : (f32, i32) -> f32 -! FAST: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @powf({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f32.i32({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, i32) -> f32 - -function test_real8(x, y, s, i) - real(8) :: x, y, test_real8 - integer(2) :: s - integer(4) :: i - test_real8 = x ** s + x ** y + x ** i -end function - -! ALL-LABEL: @_QPtest_real8 -! ALL: [[STOI:%[A-Za-z0-9._]+]] = fir.convert {{%[A-Za-z0-9._]+}} : (i16) -> i32 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f64.i32({{%[A-Za-z0-9._]+}}, [[STOI]]) : (f64, i32) -> f64 -! FAST: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @pow({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f64.i32({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, i32) -> f64 - -//--- sign.f90 -! RUN: bbc -emit-fir %t/sign.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/sign.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/sign.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/sign.f90 -! RUN: bbc -emit-fir %t/sign.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/sign.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/sign.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/sign.f90 -! RUN: bbc -emit-fir %t/sign.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/sign.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/sign.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/sign.f90 - -function test_real4(x, y) - real :: x, y, test_real4 - test_real4 = sign(x, y) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @copysignf({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 - -function test_real8(x, y) - real(8) :: x, y, test_real8 - test_real8 = sign(x, y) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @copysign({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 - -function test_real10(x, y) - real(10) :: x, y, test_real10 - test_real10 = sign(x, y) -end function - -! ALL-LABEL: @_QPtest_real10 -! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f80 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f80 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @copysignl({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f80, f80) -> f80 - -function test_real16(x, y) - real(16) :: x, y, test_real16 - test_real16 = sign(x, y) -end function - -! ALL-LABEL: @_QPtest_real16 -! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f128 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f128 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.copysign.f128({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f128, f128) -> f128 - -//--- sin.f90 -! RUN: bbc -emit-fir %t/sin.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/sin.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/sin.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/sin.f90 -! RUN: bbc -emit-fir %t/sin.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/sin.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/sin.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/sin.f90 -! RUN: bbc -emit-fir %t/sin.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/sin.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/sin.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/sin.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = sin(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @sinf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = sin(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @sin({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- sinh.f90 -! RUN: bbc -emit-fir %t/sinh.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL %t/sinh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/sinh.f90 -o - | FileCheck --check-prefixes=ALL %t/sinh.f90 -! RUN: bbc -emit-fir %t/sinh.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/sinh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/sinh.f90 -o - | FileCheck --check-prefixes=ALL %t/sinh.f90 -! RUN: bbc -emit-fir %t/sinh.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL %t/sinh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/sinh.f90 -o - | FileCheck --check-prefixes=ALL %t/sinh.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = sinh(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @sinhf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = sinh(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! ALL: {{%[A-Za-z0-9._]+}} = fir.call @sinh({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- tanh.f90 -! RUN: bbc -emit-fir %t/tanh.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/tanh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/tanh.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/tanh.f90 -! RUN: bbc -emit-fir %t/tanh.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/tanh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/tanh.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/tanh.f90 -! RUN: bbc -emit-fir %t/tanh.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/tanh.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/tanh.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/tanh.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = tanh(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tanhf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = tanh(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tanh({{%[A-Za-z0-9._]+}}) : (f64) -> f64 - -//--- tan.f90 -! RUN: bbc -emit-fir %t/tan.f90 -o - --lower-math-early=false --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/tan.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=fast %t/tan.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/tan.f90 -! RUN: bbc -emit-fir %t/tan.f90 -o - --lower-math-early=false --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/tan.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=relaxed %t/tan.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/tan.f90 -! RUN: bbc -emit-fir %t/tan.f90 -o - --lower-math-early=false --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/tan.f90 -! RUN: %flang_fc1 -emit-fir -mllvm -lower-math-early=false -mllvm -math-runtime=precise %t/tan.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/tan.f90 - -function test_real4(x) - real :: x, test_real4 - test_real4 = tan(x) -end function - -! ALL-LABEL: @_QPtest_real4 -! FAST: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f32 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f32 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tanf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 - -function test_real8(x) - real(8) :: x, test_real8 - test_real8 = tan(x) -end function - -! ALL-LABEL: @_QPtest_real8 -! FAST: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f64 -! RELAXED: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f64 -! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tan({{%[A-Za-z0-9._]+}}) : (f64) -> f64 diff --git a/flang/test/Lower/llvm-math.f90 b/flang/test/Lower/llvm-math.f90 deleted file mode 100644 --- a/flang/test/Lower/llvm-math.f90 +++ /dev/null @@ -1,219 +0,0 @@ -! RUN: bbc -emit-fir %s -o - --math-runtime=llvm --outline-intrinsics | FileCheck %s -! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=llvm -mllvm -outline-intrinsics %s -o - | FileCheck %s - - SUBROUTINE POW_WRAPPER(IN, IN2, OUT) - DOUBLE PRECISION IN, IN2 - OUT = IN ** IN2 - RETURN - END - -! CHECK-LABEL: func @_QPpow_wrapper( -! CHECK-SAME: %{{.*}}: !fir.ref{{.*}}, %{{.*}}: !fir.ref{{.*}}, %{{.*}}: !fir.ref{{.*}}) { -! CHECK-NEXT: %0 = fir.load %arg0 : !fir.ref -! CHECK-NEXT: %1 = fir.load %arg1 : !fir.ref -! CHECK-NEXT: %2 = fir.call @llvm.pow.f64(%0, %1) : (f64, f64) -> f64 - - SUBROUTINE POWF_WRAPPER(IN, IN2, OUT) - REAL IN, IN2 - OUT = IN ** IN2 - RETURN - END - -! CHECK-LABEL: func @_QPpowf_wrapper( -! CHECK-SAME: %{{.*}}: !fir.ref{{.*}}, %{{.*}}: !fir.ref{{.*}}, %{{.*}}: !fir.ref{{.*}}) { -! CHECK-NEXT: %0 = fir.load %arg0 : !fir.ref -! CHECK-NEXT: %1 = fir.load %arg1 : !fir.ref -! CHECK-NEXT: %2 = fir.call @llvm.pow.f32(%0, %1) : (f32, f32) -> f32 - - SUBROUTINE ATAN_WRAPPER(IN, OUT) - DOUBLE PRECISION IN - OUT = DATAN(IN) - RETURN - END - -! CHECK: func private @fir.atan.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @atan(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE EXP_WRAPPER(IN, OUT) - DOUBLE PRECISION IN - OUT = DEXP(IN) - RETURN - END - -! CHECK: func private @fir.exp.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @llvm.exp.f64(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE SINH_WRAPPER(IN, OUT) - DOUBLE PRECISION IN - OUT = DSINH(IN) - RETURN - END - -! CHECK: func private @fir.sinh.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @sinh(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE COSH_WRAPPER(IN, OUT) - DOUBLE PRECISION IN - OUT = DCOSH(IN) - RETURN - END - -! CHECK: func private @fir.cosh.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @cosh(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - - SUBROUTINE ATANF_WRAPPER(IN, OUT) - REAL IN - OUT = ATAN(IN) - RETURN - END - -! CHECK: func private @fir.atan.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @atanf(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE EXPF_WRAPPER(IN, OUT) - REAL IN - OUT = EXP(IN) - RETURN - END - -! CHECK: func private @fir.exp.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @llvm.exp.f32(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE SINHF_WRAPPER(IN, OUT) - REAL IN - OUT = SINH(IN) - RETURN - END - -! CHECK: func private @fir.sinh.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @sinhf(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE COSHF_WRAPPER(IN, OUT) - REAL IN - OUT = COSH(IN) - RETURN - END - -! CHECK: func private @fir.cosh.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @coshf(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE LOG_WRAPPER(IN, OUT) - DOUBLE PRECISION IN, OUT - OUT = DLOG(IN) - RETURN - END - -! CHECK: func private @fir.log.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @llvm.log.f64(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE LOG10_WRAPPER(IN, OUT) - DOUBLE PRECISION IN, OUT - OUT = DLOG10(IN) - RETURN - END - -! CHECK: func private @fir.log10.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @llvm.log10.f64(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE LOGF_WRAPPER(IN, OUT) - REAL IN, OUT - OUT = LOG(IN) - RETURN - END - -! CHECK: func private @fir.log.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @llvm.log.f32(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE LOG10F_WRAPPER(IN, OUT) - REAL IN, OUT - OUT = LOG10(IN) - RETURN - END - -! CHECK: func private @fir.log10.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @llvm.log10.f32(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE SQRT_WRAPPER(IN, OUT) - REAL :: IN, OUT - OUT = SQRT(IN) - END SUBROUTINE - -! CHECK-LABEL: func private @fir.sqrt.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @llvm.sqrt.f32(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE SQRTD_WRAPPER(IN, OUT) - REAL(KIND=8) :: IN, OUT - OUT = SQRT(IN) - END SUBROUTINE - -! CHECK-LABEL: func private @fir.sqrt.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @llvm.sqrt.f64(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE COS_WRAPPER(IN, OUT) - REAL :: IN, OUT - OUT = COS(IN) - END SUBROUTINE - -! CHECK-LABEL: func private @fir.cos.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @llvm.cos.f32(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE COSD_WRAPPER(IN, OUT) - REAL(KIND=8) :: IN, OUT - OUT = COS(IN) - END SUBROUTINE - -! CHECK-LABEL: func private @fir.cos.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @llvm.cos.f64(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } - - SUBROUTINE SIN_WRAPPER(IN, OUT) - REAL :: IN, OUT - OUT = SIN(IN) - END SUBROUTINE - -! CHECK-LABEL: func private @fir.sin.f32.f32(%arg0: f32) -! CHECK-NEXT: %0 = fir.call @llvm.sin.f32(%arg0) : (f32) -> f32 -! CHECK-NEXT: return %0 : f32 -! CHECK-NEXT: } - - SUBROUTINE SIND_WRAPPER(IN, OUT) - REAL(KIND=8) :: IN, OUT - OUT = SIN(IN) - END SUBROUTINE - -! CHECK-LABEL: func private @fir.sin.f64.f64(%arg0: f64) -! CHECK-NEXT: %0 = fir.call @llvm.sin.f64(%arg0) : (f64) -> f64 -! CHECK-NEXT: return %0 : f64 -! CHECK-NEXT: } diff --git a/flang/test/Lower/math-lowering.f90 b/flang/test/Lower/math-lowering.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/math-lowering.f90 @@ -0,0 +1,602 @@ +! RUN: split-file %s %t + +//--- abs.f90 +! RUN: bbc -emit-fir %t/abs.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/abs.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/abs.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/abs.f90 +! RUN: bbc -emit-fir %t/abs.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/abs.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/abs.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/abs.f90 +! RUN: bbc -emit-fir %t/abs.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/abs.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/abs.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/abs.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = abs(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @fabsf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = abs(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @fabs({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +function test_real16(x) + real(16) :: x, test_real16 + test_real16 = abs(x) +end function +! ALL-LABEL: @_QPtest_real16 +! FAST: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f128 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.abs {{%[A-Za-z0-9._]+}} : f128 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.fabs.f128({{%[A-Za-z0-9._]+}}) : (f128) -> f128 + +function test_complex4(c) + complex(4) :: c, test_complex4 + test_complex4 = abs(c) +end function + +! ALL-LABEL: @_QPtest_complex4 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @hypotf({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 + +function test_complex8(c) + complex(8) :: c, test_complex8 + test_complex8 = abs(c) +end function + +! ALL-LABEL: @_QPtest_complex8 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @hypot({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 + +//--- aint.f90 +! RUN: bbc -emit-fir %t/aint.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %t/aint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/aint.f90 -o - | FileCheck --check-prefixes=ALL %t/aint.f90 +! RUN: bbc -emit-fir %t/aint.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/aint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/aint.f90 -o - | FileCheck --check-prefixes=ALL %t/aint.f90 +! RUN: bbc -emit-fir %t/aint.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %t/aint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/aint.f90 -o - | FileCheck --check-prefixes=ALL %t/aint.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = aint(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.trunc.f32({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = aint(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.trunc.f64({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- anint.f90 +! RUN: bbc -emit-fir %t/anint.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/anint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/anint.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/anint.f90 +! RUN: bbc -emit-fir %t/anint.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/anint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/anint.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/anint.f90 +! RUN: bbc -emit-fir %t/anint.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/anint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/anint.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/anint.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = anint(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f32) -> f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f32) -> f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f32({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = anint(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f64) -> f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = "llvm.intr.round"({{%[A-Za-z0-9._]+}}) : (f64) -> f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.round.f64({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- atan.f90 +! RUN: bbc -emit-fir %t/atan.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/atan.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/atan.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/atan.f90 +! RUN: bbc -emit-fir %t/atan.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/atan.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/atan.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/atan.f90 +! RUN: bbc -emit-fir %t/atan.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/atan.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/atan.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/atan.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = atan(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atanf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = atan(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atan({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- atan2.f90 +! RUN: bbc -emit-fir %t/atan2.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/atan2.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/atan2.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/atan2.f90 +! RUN: bbc -emit-fir %t/atan2.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/atan2.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/atan2.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/atan2.f90 +! RUN: bbc -emit-fir %t/atan2.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/atan2.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/atan2.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/atan2.f90 + +function test_real4(x, y) + real :: x, y, test_real4 + test_real4 = atan2(x, y) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atan2f({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 + +function test_real8(x, y) + real(8) :: x, y, test_real8 + test_real8 = atan2(x, y) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.atan2 {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @atan2({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 + +//--- ceiling.f90 +! RUN: bbc -emit-fir %t/ceiling.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/ceiling.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/ceiling.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/ceiling.f90 +! RUN: bbc -emit-fir %t/ceiling.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/ceiling.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/ceiling.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/ceiling.f90 +! RUN: bbc -emit-fir %t/ceiling.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/ceiling.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/ceiling.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/ceiling.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = ceiling(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @ceilf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = ceiling(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.ceil {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @ceil({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- cos.f90 +! RUN: bbc -emit-fir %t/cos.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/cos.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/cos.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/cos.f90 +! RUN: bbc -emit-fir %t/cos.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/cos.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/cos.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/cos.f90 +! RUN: bbc -emit-fir %t/cos.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/cos.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/cos.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/cos.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = cos(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @cosf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = cos(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.cos {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @cos({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- cosh.f90 +! RUN: bbc -emit-fir %t/cosh.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %t/cosh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/cosh.f90 -o - | FileCheck --check-prefixes=ALL %t/cosh.f90 +! RUN: bbc -emit-fir %t/cosh.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/cosh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/cosh.f90 -o - | FileCheck --check-prefixes=ALL %t/cosh.f90 +! RUN: bbc -emit-fir %t/cosh.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %t/cosh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/cosh.f90 -o - | FileCheck --check-prefixes=ALL %t/cosh.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = cosh(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @coshf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = cosh(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @cosh({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- erf.f90 +! RUN: bbc -emit-fir %t/erf.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/erf.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/erf.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/erf.f90 +! RUN: bbc -emit-fir %t/erf.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/erf.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/erf.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/erf.f90 +! RUN: bbc -emit-fir %t/erf.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/erf.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/erf.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/erf.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = erf(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erff({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = erf(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.erf {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @erf({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- exp.f90 +! RUN: bbc -emit-fir %t/exp.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/exp.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/exp.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/exp.f90 +! RUN: bbc -emit-fir %t/exp.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/exp.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/exp.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/exp.f90 +! RUN: bbc -emit-fir %t/exp.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/exp.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/exp.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/exp.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = exp(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @expf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = exp(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.exp {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @exp({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- floor.f90 +! RUN: bbc -emit-fir %t/floor.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/floor.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/floor.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/floor.f90 +! RUN: bbc -emit-fir %t/floor.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/floor.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/floor.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/floor.f90 +! RUN: bbc -emit-fir %t/floor.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/floor.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/floor.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/floor.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = floor(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @floorf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = floor(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.floor {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @floor({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- log.f90 +! RUN: bbc -emit-fir %t/log.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/log.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/log.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/log.f90 +! RUN: bbc -emit-fir %t/log.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/log.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/log.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/log.f90 +! RUN: bbc -emit-fir %t/log.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/log.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/log.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/log.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = log(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @logf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = log(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.log {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @log({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- log10.f90 +! RUN: bbc -emit-fir %t/log10.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/log10.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/log10.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/log10.f90 +! RUN: bbc -emit-fir %t/log10.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/log10.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/log10.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/log10.f90 +! RUN: bbc -emit-fir %t/log10.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/log10.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/log10.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/log10.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = log10(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @log10f({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = log10(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.log10 {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @log10({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- nint.f90 +! RUN: bbc -emit-fir %t/nint.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %t/nint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/nint.f90 -o - | FileCheck --check-prefixes=ALL %t/nint.f90 +! RUN: bbc -emit-fir %t/nint.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/nint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/nint.f90 -o - | FileCheck --check-prefixes=ALL %t/nint.f90 +! RUN: bbc -emit-fir %t/nint.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %t/nint.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/nint.f90 -o - | FileCheck --check-prefixes=ALL %t/nint.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = nint(x, 4) + nint(x, 8) +end function + +! ALL-LABEL: @_QPtest_real4 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i32.f32({{%[A-Za-z0-9._]+}}) : (f32) -> i32 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i64.f32({{%[A-Za-z0-9._]+}}) : (f32) -> i64 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = nint(x, 4) + nint(x, 8) +end function + +! ALL-LABEL: @_QPtest_real8 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i32.f64({{%[A-Za-z0-9._]+}}) : (f64) -> i32 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.lround.i64.f64({{%[A-Za-z0-9._]+}}) : (f64) -> i64 + +//--- exponentiation.f90 +! RUN: bbc -emit-fir %t/exponentiation.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/exponentiation.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/exponentiation.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/exponentiation.f90 +! RUN: bbc -emit-fir %t/exponentiation.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/exponentiation.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/exponentiation.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/exponentiation.f90 +! RUN: bbc -emit-fir %t/exponentiation.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/exponentiation.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/exponentiation.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/exponentiation.f90 + +function test_real4(x, y, s, i) + real :: x, y, test_real4 + integer(2) :: s + integer(4) :: i + test_real4 = x ** s + x ** y + x ** i +end function + +! ALL-LABEL: @_QPtest_real4 +! ALL: [[STOI:%[A-Za-z0-9._]+]] = fir.convert {{%[A-Za-z0-9._]+}} : (i16) -> i32 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f32.i32({{%[A-Za-z0-9._]+}}, [[STOI]]) : (f32, i32) -> f32 +! FAST: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @powf({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f32.i32({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, i32) -> f32 + +function test_real8(x, y, s, i) + real(8) :: x, y, test_real8 + integer(2) :: s + integer(4) :: i + test_real8 = x ** s + x ** y + x ** i +end function + +! ALL-LABEL: @_QPtest_real8 +! ALL: [[STOI:%[A-Za-z0-9._]+]] = fir.convert {{%[A-Za-z0-9._]+}} : (i16) -> i32 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f64.i32({{%[A-Za-z0-9._]+}}, [[STOI]]) : (f64, i32) -> f64 +! FAST: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.powf {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @pow({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @llvm.powi.f64.i32({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, i32) -> f64 + +//--- sign.f90 +! RUN: bbc -emit-fir %t/sign.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/sign.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/sign.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/sign.f90 +! RUN: bbc -emit-fir %t/sign.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/sign.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/sign.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/sign.f90 +! RUN: bbc -emit-fir %t/sign.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/sign.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/sign.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/sign.f90 + +function test_real4(x, y) + real :: x, y, test_real4 + test_real4 = sign(x, y) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @copysignf({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f32, f32) -> f32 + +function test_real8(x, y) + real(8) :: x, y, test_real8 + test_real8 = sign(x, y) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @copysign({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f64, f64) -> f64 + +function test_real10(x, y) + real(10) :: x, y, test_real10 + test_real10 = sign(x, y) +end function + +! ALL-LABEL: @_QPtest_real10 +! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f80 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f80 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @copysignl({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f80, f80) -> f80 + +function test_real16(x, y) + real(16) :: x, y, test_real16 + test_real16 = sign(x, y) +end function + +! ALL-LABEL: @_QPtest_real16 +! FAST: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f128 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.copysign {{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}} : f128 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @llvm.copysign.f128({{%[A-Za-z0-9._]+}}, {{%[A-Za-z0-9._]+}}) : (f128, f128) -> f128 + +//--- sin.f90 +! RUN: bbc -emit-fir %t/sin.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/sin.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/sin.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/sin.f90 +! RUN: bbc -emit-fir %t/sin.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/sin.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/sin.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/sin.f90 +! RUN: bbc -emit-fir %t/sin.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/sin.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/sin.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/sin.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = sin(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @sinf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = sin(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.sin {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @sin({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- sinh.f90 +! RUN: bbc -emit-fir %t/sinh.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL %t/sinh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/sinh.f90 -o - | FileCheck --check-prefixes=ALL %t/sinh.f90 +! RUN: bbc -emit-fir %t/sinh.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL %t/sinh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/sinh.f90 -o - | FileCheck --check-prefixes=ALL %t/sinh.f90 +! RUN: bbc -emit-fir %t/sinh.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL %t/sinh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/sinh.f90 -o - | FileCheck --check-prefixes=ALL %t/sinh.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = sinh(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @sinhf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = sinh(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! ALL: {{%[A-Za-z0-9._]+}} = fir.call @sinh({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- tanh.f90 +! RUN: bbc -emit-fir %t/tanh.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/tanh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/tanh.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/tanh.f90 +! RUN: bbc -emit-fir %t/tanh.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/tanh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/tanh.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/tanh.f90 +! RUN: bbc -emit-fir %t/tanh.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/tanh.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/tanh.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/tanh.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = tanh(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tanhf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = tanh(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.tanh {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tanh({{%[A-Za-z0-9._]+}}) : (f64) -> f64 + +//--- tan.f90 +! RUN: bbc -emit-fir %t/tan.f90 -o - --math-runtime=fast | FileCheck --check-prefixes=ALL,FAST %t/tan.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=fast %t/tan.f90 -o - | FileCheck --check-prefixes=ALL,FAST %t/tan.f90 +! RUN: bbc -emit-fir %t/tan.f90 -o - --math-runtime=relaxed | FileCheck --check-prefixes=ALL,RELAXED %t/tan.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=relaxed %t/tan.f90 -o - | FileCheck --check-prefixes=ALL,RELAXED %t/tan.f90 +! RUN: bbc -emit-fir %t/tan.f90 -o - --math-runtime=precise | FileCheck --check-prefixes=ALL,PRECISE %t/tan.f90 +! RUN: %flang_fc1 -emit-fir -mllvm -math-runtime=precise %t/tan.f90 -o - | FileCheck --check-prefixes=ALL,PRECISE %t/tan.f90 + +function test_real4(x) + real :: x, test_real4 + test_real4 = tan(x) +end function + +! ALL-LABEL: @_QPtest_real4 +! FAST: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f32 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f32 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tanf({{%[A-Za-z0-9._]+}}) : (f32) -> f32 + +function test_real8(x) + real(8) :: x, test_real8 + test_real8 = tan(x) +end function + +! ALL-LABEL: @_QPtest_real8 +! FAST: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f64 +! RELAXED: {{%[A-Za-z0-9._]+}} = math.tan {{%[A-Za-z0-9._]+}} : f64 +! PRECISE: {{%[A-Za-z0-9._]+}} = fir.call @tan({{%[A-Za-z0-9._]+}}) : (f64) -> f64 diff --git a/flang/test/Lower/power-operator.f90 b/flang/test/Lower/power-operator.f90 --- a/flang/test/Lower/power-operator.f90 +++ b/flang/test/Lower/power-operator.f90 @@ -7,14 +7,14 @@ real :: x, z integer :: y z = x ** y - ! CHECK: call @__fs_powi_1 + ! CHECK: call @llvm.powi.f32.i32 end subroutine ! CHECK-LABEL: pow_r4_r4 subroutine pow_r4_r4(x, y, z) real :: x, z, y z = x ** y - ! CHECK: call @__fs_pow_1 + ! CHECK: math.powf %{{.*}}, %{{.*}} : f32 end subroutine ! CHECK-LABEL: pow_r4_i8 @@ -30,7 +30,7 @@ real(8) :: x, z integer :: y z = x ** y - ! CHECK: call @__fd_powi_1 + ! CHECK: call @llvm.powi.f64.i32 end subroutine ! CHECK-LABEL: pow_r8_i8 @@ -45,7 +45,7 @@ subroutine pow_r8_r8(x, y, z) real(8) :: x, z, y z = x ** y - ! CHECK: call @__fd_pow_1 + ! CHECK: math.powf %{{.*}}, %{{.*}} : f64 end subroutine ! CHECK-LABEL: pow_r4_r8 @@ -54,7 +54,7 @@ real(8) :: z, y z = x ** y ! CHECK: %{{.*}} = fir.convert %{{.*}} : (f32) -> f64 - ! CHECK: call @__fd_pow_1 + ! CHECK: math.powf %{{.*}}, %{{.*}} : f64 end subroutine ! CHECK-LABEL: pow_i4_i4 diff --git a/flang/test/Lower/sqrt.f90 b/flang/test/Lower/sqrt.f90 --- a/flang/test/Lower/sqrt.f90 +++ b/flang/test/Lower/sqrt.f90 @@ -30,10 +30,10 @@ end subroutine ! CHECK-LABEL: @fir.sqrt.f32.f32 -! CHECK: fir.call {{.*}}mth_i_sqrt +! CHECK: math.sqrt %{{.*}} : f32 ! CHECK-LABEL: @fir.sqrt.f64.f64 -! CHECK: fir.call {{.*}}mth_i_dsqrt +! CHECK: math.sqrt %{{.*}} : f64 ! CHECK-LABEL: func private @fir.sqrt.z4.z4 ! CHECK: fir.call {{.*}}fc_sqrt diff --git a/flang/test/Lower/trigonometric-intrinsics.f90 b/flang/test/Lower/trigonometric-intrinsics.f90 --- a/flang/test/Lower/trigonometric-intrinsics.f90 +++ b/flang/test/Lower/trigonometric-intrinsics.f90 @@ -142,10 +142,10 @@ end subroutine ! CHECK-LABEL: @fir.atan.f32.f32 -! CHECK: fir.call {{.*}}atan +! CHECK: math.atan %{{.*}} : f32 ! CHECK-LABEL: @fir.atan.f64.f64 -! CHECK: fir.call {{.*}}atan +! CHECK: math.atan %{{.*}} : f64 ! CHECK-LABEL: @fir.atan.z4.z4 ! CHECK: fir.call {{.*}}atan @@ -154,10 +154,10 @@ ! CHECK: fir.call {{.*}}atan ! CHECK-LABEL: @fir.cos.f32.f32 -! CHECK: fir.call {{.*}}cos +! CHECK: math.cos %{{.*}} : f32 ! CHECK-LABEL: @fir.cos.f64.f64 -! CHECK: fir.call {{.*}}cos +! CHECK: math.cos %{{.*}} : f64 ! CHECK-LABEL: @fir.cos.z4.z4 ! CHECK: fir.call {{.*}}cos @@ -178,10 +178,10 @@ ! CHECK: fir.call {{.*}}cosh ! CHECK-LABEL: @fir.sin.f32.f32 -! CHECK: fir.call {{.*}}sin +! CHECK: math.sin %{{.*}} : f32 ! CHECK-LABEL: @fir.sin.f64.f64 -! CHECK: fir.call {{.*}}sin +! CHECK: math.sin %{{.*}} : f64 ! CHECK-LABEL: @fir.sin.z4.z4 ! CHECK: fir.call {{.*}}sin