[clang] [llvm] [X86][AMDLIBM] - Lower scalar call to AMD's AOCL fast scalar call (PR #213676)
Rohit Aggarwal via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 02:01:36 PDT 2026
https://github.com/rohitaggarwal007 updated https://github.com/llvm/llvm-project/pull/213676
>From 12a7df2a7a14d72dbab110d17118d6bce0bf6ee3 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Mon, 3 Aug 2026 19:00:50 +0530
Subject: [PATCH 01/10] [X86][AMDLIBM] - Add scalar AMD AOCL fast-call
lowering (-fsclrlib=AMDLIBM)
Under fast-math at -O3, scalar math library calls (e.g. tan, exp)
are rewritten to their AMD AOCL fast-call equivalents (e.g. amd_fasttan,
amd_fastexp) on X86 targets.
LLVM:
- New X86 MachineFunctionPass X86GenScalarAmdFastCalls, run in
addMachineSSAOptimization at CodeGenOptLevel::Aggressive.
- TargetLibraryInfo gains a scalar-math-library selection (ScalarLibrary enum,
addScalarFunctionsFromMathLib / getScalarFunctionFromMathLib /
getScalarMathLib / setScalarMathLib), populated from the new
ScalarAOCLFuncs.def mapping and driven by the -scalar-library=AMDLIBM
cl::opt (usable with llc and the LTO plugin).
- The rewrite is gated on -scalar-library=AMDLIBM plus a function-level
fast-math signal (per-operation fast-math flags are no longer available at
this late machine pass in upstream codegen).
Clang:
- New -fsclrlib= driver/CC1 flag with a CodeGenOptions ScalarLib enum,
applied in BackendUtil and forwarded to LTO as -plugin-opt=-scalar-library=.
Tests:
- llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll (llc path, incl. a negative
no-fast-math case).
- clang/test/CodeGen/X86/aocl-fast-scalar-calls.c (driver path).
- aocl-fast-scalar-calls-mappings.ll: float variants (tanf, powf), a *_finite
alias (__exp_finite), inverse-trig (acos, atan), and negative cases for
math calls with no AOCL mapping (pow(double), cbrt).
- aocl-fast-scalar-calls-i686.ll: 32-bit X86 coverage (tan, expf).
- aocl-fast-scalar-calls.c: add a single-precision case (tanf) and an
unmapped negative case (cbrt) to the clang driver test.
---
clang/include/clang/Basic/CodeGenOptions.def | 3 +
clang/include/clang/Basic/CodeGenOptions.h | 6 +
clang/include/clang/Options/Options.td | 7 +
clang/lib/CodeGen/BackendUtil.cpp | 14 +
clang/lib/Driver/ToolChains/Clang.cpp | 11 +
clang/lib/Driver/ToolChains/CommonArgs.cpp | 8 +
.../test/CodeGen/X86/aocl-fast-scalar-calls.c | 40 +++
.../include/llvm/Analysis/ScalarAOCLFuncs.def | 80 ++++++
.../include/llvm/Analysis/TargetLibraryInfo.h | 33 +++
llvm/lib/Analysis/TargetLibraryInfo.cpp | 52 ++++
llvm/lib/Target/X86/CMakeLists.txt | 1 +
llvm/lib/Target/X86/X86.h | 6 +
.../Target/X86/X86GenScalarAmdFastCalls.cpp | 176 ++++++++++++
llvm/lib/Target/X86/X86TargetMachine.cpp | 5 +
.../X86/aocl-fast-scalar-calls-i686.ll | 31 +++
.../X86/aocl-fast-scalar-calls-mappings.ll | 124 +++++++++
.../CodeGen/X86/aocl-fast-scalar-calls.ll | 63 +++++
llvm/test/CodeGen/X86/veclib-llvm.sincos.s | 258 ++++++++++++++++++
18 files changed, 918 insertions(+)
create mode 100644 clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
create mode 100644 llvm/include/llvm/Analysis/ScalarAOCLFuncs.def
create mode 100644 llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
create mode 100644 llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
create mode 100644 llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
create mode 100644 llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
create mode 100644 llvm/test/CodeGen/X86/veclib-llvm.sincos.s
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index 2a045386770059..d76727f70ab439 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -419,6 +419,9 @@ VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX, Benign)
// Vector functions library to use.
ENUM_CODEGENOPT(VecLib, VectorLibrary, 4, VectorLibrary::NoLibrary, Benign)
+// Scalar math functions library to use.
+ENUM_CODEGENOPT(ScalarLib, ScalarLibrary, 1, Default_Scalar_Library, Benign)
+
/// The default TLS model to use.
ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel, Benign)
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 17f367bc02607f..43d45d0261f211 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -110,6 +110,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
OnlyAlwaysInlining // Only run the always inlining pass.
};
+ /// Scalar math functions library to use with -fsclrlib=.
+ enum ScalarLibrary {
+ Default_Scalar_Library, // Use default library.
+ SCALAR_AMDLIBM // AMD scalar math library.
+ };
+
enum ObjCDispatchMethodKind {
Legacy = 0,
NonLegacy = 1,
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 37e5c3199a0031..675ada8a49458f 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4025,6 +4025,13 @@ def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>,
NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "SLEEF",
"Darwin_libsystem_m", "ArmPL", "AMDLIBM", "NoLibrary"]>,
MarshallingInfoEnum<CodeGenOpts<"VecLib">, "NoLibrary">;
+def fsclrlib : Joined<["-"], "fsclrlib=">, Group<f_Group>,
+ Visibility<[ClangOption, CC1Option]>,
+ HelpText<"Use the given scalar math functions library.">,
+ Values<"AMDLIBM,none">,
+ NormalizedValuesScope<"CodeGenOptions">,
+ NormalizedValues<["SCALAR_AMDLIBM", "Default_Scalar_Library"]>,
+ MarshallingInfoEnum<CodeGenOpts<"ScalarLib">, "Default_Scalar_Library">;
def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>,
Alias<flax_vector_conversions_EQ>, AliasArgs<["none"]>;
def fno_implicit_module_maps : Flag <["-"], "fno-implicit-module-maps">, Group<f_Group>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index c09a8f7c0d6795..439b0461d35b58 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -146,6 +146,19 @@ static std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
return FileName;
}
+/// Populate the scalar math library mappings on \p TLII according to the
+/// -fsclrlib= selection.
+static void addScalarMathLibrary(TargetLibraryInfoImpl &TLII,
+ const CodeGenOptions &CodeGenOpts) {
+ switch (CodeGenOpts.getScalarLib()) {
+ case CodeGenOptions::SCALAR_AMDLIBM:
+ TLII.addScalarFunctionsFromMathLib(TargetLibraryInfoImpl::SCALAR_AMDLIBM);
+ break;
+ case CodeGenOptions::Default_Scalar_Library:
+ break;
+ }
+}
+
namespace {
class EmitAssemblyHelper {
@@ -989,6 +1002,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
// preset TLI.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
+ addScalarMathLibrary(*TLII, CodeGenOpts);
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
// Register all the basic analyses with the managers.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index ab852bf0e0043d..7bc4cccf3c8090 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6035,6 +6035,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
A->render(Args, CmdArgs);
}
+ if (Arg *A = Args.getLastArg(options::OPT_fsclrlib)) {
+ StringRef Name = A->getValue();
+ if (Name == "AMDLIBM") {
+ if (Triple.getArch() != llvm::Triple::x86 &&
+ Triple.getArch() != llvm::Triple::x86_64)
+ D.Diag(diag::err_drv_unsupported_opt_for_target)
+ << Name << Triple.getArchName();
+ }
+ A->render(Args, CmdArgs);
+ }
+
if (Args.hasFlag(options::OPT_fmerge_all_constants,
options::OPT_fno_merge_all_constants, false))
CmdArgs.push_back("-fmerge-all-constants");
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 64859a318485b3..727ea9babff7f4 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1154,6 +1154,14 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
}
+ // Pass scalar math library arguments to LTO.
+ if (Arg *ArgScalarLib = Args.getLastArg(options::OPT_fsclrlib)) {
+ StringRef Name = ArgScalarLib->getValue();
+ if (Name == "AMDLIBM")
+ CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
+ "-scalar-library=" + Name));
+ }
+
// Try to pass driver level flags relevant to LTO code generation down to
// the plugin.
diff --git a/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c b/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
new file mode 100644
index 00000000000000..50a512ebc2a5ed
--- /dev/null
+++ b/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
@@ -0,0 +1,40 @@
+// Verify that the -fsclrlib=AMDLIBM driver flag, together with fast-math at -O3,
+// rewrites scalar math library calls into their AMD AOCL fast-call equivalents
+// for X86, and leaves them untouched without the flag.
+
+// REQUIRES: x86-registered-target
+
+// RUN: %clang --target=x86_64-unknown-linux-gnu -O3 -ffast-math \
+// RUN: -fsclrlib=AMDLIBM -S %s -o - | FileCheck %s --check-prefix=AMD
+// RUN: %clang --target=x86_64-unknown-linux-gnu -O3 -ffast-math \
+// RUN: -S %s -o - | FileCheck %s --check-prefix=STD
+
+double tan(double);
+double exp(double);
+float tanf(float);
+double cbrt(double);
+
+double call_tan(double x) { return tan(x) + x; }
+// AMD-LABEL: call_tan:
+// AMD: callq{{.*}}amd_fasttan
+// STD-LABEL: call_tan:
+// STD: callq{{.*}}tan
+
+double call_exp(double x) { return exp(x) + x; }
+// AMD-LABEL: call_exp:
+// AMD: callq{{.*}}amd_fastexp
+// STD-LABEL: call_exp:
+// STD: callq{{.*}}exp
+
+// Single-precision variant is rewritten too.
+float call_tanf(float x) { return tanf(x) + x; }
+// AMD-LABEL: call_tanf:
+// AMD: callq{{.*}}amd_fasttanf
+// STD-LABEL: call_tanf:
+// STD: callq{{.*}}tanf
+
+// cbrt has no AOCL mapping and must stay even with the option enabled.
+double call_cbrt(double x) { return cbrt(x) + x; }
+// AMD-LABEL: call_cbrt:
+// AMD-NOT: amd_fast
+// AMD: callq{{.*}}cbrt
diff --git a/llvm/include/llvm/Analysis/ScalarAOCLFuncs.def b/llvm/include/llvm/Analysis/ScalarAOCLFuncs.def
new file mode 100644
index 00000000000000..906b1612afa5c2
--- /dev/null
+++ b/llvm/include/llvm/Analysis/ScalarAOCLFuncs.def
@@ -0,0 +1,80 @@
+//===-- ScalarAOCLFuncs.def - AMD scalar math library mappings --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This .def file creates a mapping from standard scalar math functions to
+// their corresponding fast entry points in the AMD AOCL scalar math library.
+// The lowering is only legal under fast-math semantics.
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(TLI_DEFINE_SCALAR_AOCL_FUNCS)
+#define TLI_DEFINE_SCALAR_AOCL_FUNC(SCAL, AOCLENTRY) {SCAL, AOCLENTRY},
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("acosf", "amd_fastacosf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__acosf_finite", "amd_fastacosf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("acos", "amd_fastacos")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__acos_finite", "amd_fastacos")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("asinf", "amd_fastasinf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__asinf_finite", "amd_fastasinf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("asin", "amd_fastasin")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__asin_finite", "amd_fastasin")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("atanf", "amd_fastatanf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__atanf_finite", "amd_fastatanf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("atan", "amd_fastatan")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__atan_finite", "amd_fastatan")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("cosf", "amd_fastcosf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__cosf_finite", "amd_fastcosf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.cos.f32", "amd_fastcosf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("cos", "amd_fastcos")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__cos_finite", "amd_fastcos")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.cos.f64", "amd_fastcos")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("erff", "amd_fasterff")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__erff_finite", "amd_fasterff")
+TLI_DEFINE_SCALAR_AOCL_FUNC("erf", "amd_fasterf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__erf_finite", "amd_fasterf")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("expf", "amd_fastexpf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__expf_finite", "amd_fastexpf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.exp.f32", "amd_fastexpf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("exp", "amd_fastexp")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__exp_finite", "amd_fastexp")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.exp.f64", "amd_fastexp")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("logf", "amd_fastlogf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__logf_finite", "amd_fastlogf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.log.f32", "amd_fastlogf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("log", "amd_fastlog")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__log_finite", "amd_fastlog")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.log.f64", "amd_fastlog")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("powf", "amd_fastpowf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__powf_finite", "amd_fastpowf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.pow.f32", "amd_fastpowf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("pow", "amd_fastpow")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__pow_finite", "amd_fastpow")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.pow.f64", "amd_fastpow")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("sinf", "amd_fastsinf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__sinf_finite", "amd_fastsinf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.sin.f32", "amd_fastsinf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("sin", "amd_fastsin")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__sin_finite", "amd_fastsin")
+TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.sin.f64", "amd_fastsin")
+
+TLI_DEFINE_SCALAR_AOCL_FUNC("tanf", "amd_fasttanf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__tanf_finite", "amd_fasttanf")
+TLI_DEFINE_SCALAR_AOCL_FUNC("tan", "amd_fasttan")
+TLI_DEFINE_SCALAR_AOCL_FUNC("__tan_finite", "amd_fasttan")
+#endif
+
+#undef TLI_DEFINE_SCALAR_AOCL_FUNCS
+#undef TLI_DEFINE_SCALAR_AOCL_FUNC
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index abbf2db6e27cb2..30da53fc0addb8 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -122,12 +122,25 @@ class TargetLibraryInfoImpl {
/// on VectorFnName rather than ScalarFnName.
std::vector<VecDesc> ScalarDescs;
+ /// Mapping from a standard scalar math function name to its AMD scalar math
+ /// library fast-call equivalent (e.g. "tan" -> "amd_fasttan"). Populated when
+ /// an AMD scalar math library is selected.
+ DenseMap<StringRef, StringRef> LibScalarFunctions;
+
/// Return true if the function type FTy is valid for the library function
/// F, regardless of whether the function is available.
LLVM_ABI bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
const Module &M) const;
public:
+ /// Scalar math library selection used for lowering standard scalar math
+ /// calls to faster, library-specific entry points.
+ enum ScalarLibrary {
+ Default_Scalar_Library, // Use default library.
+ SCALAR_AMDLIBM // AMD scalar math library.
+ };
+ ScalarLibrary ScalarMathLib = Default_Scalar_Library;
+
TargetLibraryInfoImpl() = delete;
LLVM_ABI explicit TargetLibraryInfoImpl(
const Triple &T, VectorLibrary VecLib = VectorLibrary::NoLibrary);
@@ -197,6 +210,20 @@ class TargetLibraryInfoImpl {
addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib,
const llvm::Triple &TargetTriple);
+ /// Populate the scalar math function mappings for the given scalar library
+ /// and record it as the selected scalar math library.
+ LLVM_ABI void addScalarFunctionsFromMathLib(enum ScalarLibrary ScalarLib);
+
+ /// Return the library-specific scalar function name for \p F, or an empty
+ /// StringRef if no mapping exists.
+ LLVM_ABI StringRef getScalarFunctionFromMathLib(StringRef F) const;
+
+ /// Return the currently selected scalar math library.
+ LLVM_ABI ScalarLibrary getScalarMathLib() const;
+
+ /// Set the selected scalar math library.
+ LLVM_ABI void setScalarMathLib(enum ScalarLibrary ScalarLib);
+
/// Return true if the function F has a vector equivalent with vectorization
/// factor VF.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const {
@@ -406,6 +433,12 @@ class TargetLibraryInfo {
bool Masked) const {
return Impl->getVectorMappingInfo(F, VF, Masked);
}
+ StringRef getScalarFunctionFromMathLib(StringRef F) const {
+ return Impl->getScalarFunctionFromMathLib(F);
+ }
+ TargetLibraryInfoImpl::ScalarLibrary getScalarMathLib() const {
+ return Impl->getScalarMathLib();
+ }
/// Tests if the function is both available and a candidate for optimized code
/// generation.
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index c3469979d72047..3481c5e5562821 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -18,9 +18,18 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/SystemLibraries.h"
#include "llvm/InitializePasses.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/TargetParser/Triple.h"
using namespace llvm;
+static cl::opt<TargetLibraryInfoImpl::ScalarLibrary> ClScalarLibrary(
+ "scalar-library", cl::Hidden, cl::desc("Scalar functions library"),
+ cl::init(TargetLibraryInfoImpl::Default_Scalar_Library),
+ cl::values(clEnumValN(TargetLibraryInfoImpl::Default_Scalar_Library, "none",
+ "Use default library"),
+ clEnumValN(TargetLibraryInfoImpl::SCALAR_AMDLIBM, "AMDLIBM",
+ "AMD scalar math library")));
+
#define GET_TARGET_LIBRARY_INFO_STRING_TABLE
#include "llvm/Analysis/TargetLibraryInfo.inc"
@@ -913,6 +922,7 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T,
memset(AvailableArray, -1, sizeof(AvailableArray));
initialize(*this, T, StandardNamesStrTable, VecLib);
+ addScalarFunctionsFromMathLib(ClScalarLibrary);
}
TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
@@ -924,6 +934,8 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
VectorDescs = TLI.VectorDescs;
ScalarDescs = TLI.ScalarDescs;
+ LibScalarFunctions = TLI.LibScalarFunctions;
+ ScalarMathLib = TLI.ScalarMathLib;
}
TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
@@ -937,6 +949,8 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
AvailableArray);
VectorDescs = TLI.VectorDescs;
ScalarDescs = TLI.ScalarDescs;
+ LibScalarFunctions = TLI.LibScalarFunctions;
+ ScalarMathLib = TLI.ScalarMathLib;
}
TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
@@ -948,6 +962,8 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoI
SizeOfInt = TLI.SizeOfInt;
IsErrnoFunctionCall = TLI.IsErrnoFunctionCall;
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
+ LibScalarFunctions = TLI.LibScalarFunctions;
+ ScalarMathLib = TLI.ScalarMathLib;
return *this;
}
@@ -961,6 +977,8 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&
IsErrnoFunctionCall = TLI.IsErrnoFunctionCall;
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
AvailableArray);
+ LibScalarFunctions = TLI.LibScalarFunctions;
+ ScalarMathLib = TLI.ScalarMathLib;
return *this;
}
@@ -1413,6 +1431,40 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
}
}
+void TargetLibraryInfoImpl::addScalarFunctionsFromMathLib(
+ enum ScalarLibrary ScalarLib) {
+ setScalarMathLib(ScalarLib);
+ switch (ScalarLib) {
+ case ScalarLibrary::SCALAR_AMDLIBM: {
+ const DenseMap<StringRef, StringRef> ScalarAOCLFuncs = {
+#define TLI_DEFINE_SCALAR_AOCL_FUNCS
+#include "llvm/Analysis/ScalarAOCLFuncs.def"
+ };
+ LibScalarFunctions.insert(ScalarAOCLFuncs.begin(), ScalarAOCLFuncs.end());
+ break;
+ }
+ case ScalarLibrary::Default_Scalar_Library:
+ break;
+ }
+}
+
+void TargetLibraryInfoImpl::setScalarMathLib(enum ScalarLibrary ScalarLib) {
+ ScalarMathLib = ScalarLib;
+}
+
+StringRef TargetLibraryInfoImpl::getScalarFunctionFromMathLib(
+ StringRef ScalarFnName) const {
+ auto Iter = LibScalarFunctions.find(ScalarFnName);
+ if (Iter == LibScalarFunctions.end())
+ return StringRef();
+ return Iter->second;
+}
+
+TargetLibraryInfoImpl::ScalarLibrary
+TargetLibraryInfoImpl::getScalarMathLib() const {
+ return ScalarMathLib;
+}
+
bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
funcName = sanitizeFunctionName(funcName);
if (funcName.empty())
diff --git a/llvm/lib/Target/X86/CMakeLists.txt b/llvm/lib/Target/X86/CMakeLists.txt
index a053eb85017019..cb6c38e8459a9d 100644
--- a/llvm/lib/Target/X86/CMakeLists.txt
+++ b/llvm/lib/Target/X86/CMakeLists.txt
@@ -56,6 +56,7 @@ set(sources
X86FlagsCopyLowering.cpp
X86FloatingPoint.cpp
X86FrameLowering.cpp
+ X86GenScalarAmdFastCalls.cpp
X86ISelDAGToDAG.cpp
X86ISelLowering.cpp
X86ISelLoweringCall.cpp
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index eef4de389a7def..e790a602e0f082 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -483,6 +483,12 @@ class X86ArgumentStackSlotPass
FunctionPass *createX86ArgumentStackSlotLegacyPass();
+/// This pass rewrites scalar math library calls (e.g. tan) to their AMD AOCL
+/// fast-call equivalents (e.g. amd_fasttan) under fast-math semantics.
+FunctionPass *createX86GenScalarAmdFastCallsPass();
+void initializeX86GenScalarAmdFastCallsPass(PassRegistry &);
+extern char &X86GenScalarAmdFastCallsID;
+
void initializeCompressEVEXLegacyPass(PassRegistry &);
void initializeX86FixupBWInstLegacyPass(PassRegistry &);
void initializeFixupLEAsLegacyPass(PassRegistry &);
diff --git a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp b/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
new file mode 100644
index 00000000000000..85544a2436c730
--- /dev/null
+++ b/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
@@ -0,0 +1,176 @@
+//===-- X86GenScalarAmdFastCalls.cpp --------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This transformation converts standard scalar math function calls into their
+// corresponding AMD AOCL scalar library entries for X86 targets, e.g.:
+// tan ---> amd_fasttan
+// Such lowering is only legal under fast-math semantics and when the AMD
+// scalar math library has been selected (-scalar-library=AMDLIBM /
+// -fsclrlib=AMDLIBM).
+//
+//===----------------------------------------------------------------------===//
+
+#include "X86.h"
+#include "X86Subtarget.h"
+#include "X86TargetMachine.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineOperand.h"
+#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
+#include "llvm/CodeGen/TargetPassConfig.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "x86-gen-scalar-aocl"
+
+using namespace llvm;
+
+namespace {
+
+class X86GenScalarAmdFastCalls : public MachineFunctionPass {
+public:
+ static char ID;
+
+ X86GenScalarAmdFastCalls() : MachineFunctionPass(ID) {}
+
+ bool runOnMachineFunction(MachineFunction &F) override;
+
+ StringRef getPassName() const override {
+ return "X86 Generate Scalar AOCL Entries";
+ }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.addRequired<TargetLibraryInfoWrapperPass>();
+ AU.addRequired<MachineOptimizationRemarkEmitterPass>();
+ MachineFunctionPass::getAnalysisUsage(AU);
+ }
+
+private:
+ TargetLibraryInfo *TLI = nullptr;
+ MachineOptimizationRemarkEmitter *ORE = nullptr;
+ bool isCandidateSafeToLower(MachineInstr *MI) const;
+ bool createScalarAOCLCall(MachineInstr *MI) const;
+};
+
+} // namespace
+
+// Rewriting a scalar math call to its AOCL fast-call variant is only legal
+// under fast-math semantics. By the time this late machine pass runs, the
+// per-operation fast-math flags carried by the original call have already been
+// lowered away, so we rely on the function-level fast-math attribute that the
+// frontend sets under -ffast-math. Together with the explicit
+// -scalar-library=AMDLIBM opt-in (checked in runOnMachineFunction) this gates
+// the transformation.
+bool X86GenScalarAmdFastCalls::isCandidateSafeToLower(MachineInstr *MI) const {
+ const Function &F = MI->getMF()->getFunction();
+ return F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool();
+}
+
+/// Lowers scalar math functions to scalar AOCL functions.
+/// e.g.: tan --> amd_fasttan
+/// The callsite symbol is updated during lowering.
+bool X86GenScalarAmdFastCalls::createScalarAOCLCall(MachineInstr *MI) const {
+ StringRef CallSiteName = "";
+ StringRef LibScalarFnName = "";
+ if (MI->getOperand(0).isSymbol()) {
+ CallSiteName = MI->getOperand(0).getSymbolName();
+ } else if (MI->getOperand(0).isGlobal()) {
+ CallSiteName = MI->getOperand(0).getGlobal()->getName();
+ } else {
+ return false;
+ }
+
+ LLVM_DEBUG(dbgs() << "Candidate Func = " << CallSiteName << "\n";);
+ if (CallSiteName.empty()) {
+ return false;
+ }
+ LibScalarFnName = TLI->getScalarFunctionFromMathLib(CallSiteName);
+ if (LibScalarFnName.empty()) {
+ LLVM_DEBUG(dbgs() << "Fast call not supported\n";);
+ return false;
+ }
+ LLVM_DEBUG(dbgs() << "Candidate Func has fast Call variant available = "
+ << LibScalarFnName << "\n";);
+ MI->getOperand(0).ChangeToES(LibScalarFnName.data(),
+ MI->getOperand(0).getTargetFlags());
+
+ LLVM_DEBUG(dbgs() << "Successfully replaced with fastcall= " << LibScalarFnName
+ << "\n";);
+
+ ORE->emit([&]() {
+ return MachineOptimizationRemark(DEBUG_TYPE, "Passed", MI->getDebugLoc(),
+ MI->getParent())
+ << "Successfully replaced with fastcall= " << LibScalarFnName
+ << "\n";
+ });
+ return true;
+}
+
+bool X86GenScalarAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
+ bool Changed = false;
+
+ if (skipFunction(MF.getFunction()))
+ return Changed;
+ if (MF.getFunction().isDeclaration())
+ return Changed;
+ SmallVector<MachineInstr *, 4> Callsites;
+ for (auto &BB : MF) {
+ for (auto &I : BB) {
+ if (I.isCall()) {
+ Callsites.push_back(&I);
+ }
+ }
+ }
+
+ if (Callsites.empty()) {
+ return Changed;
+ }
+
+ TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(MF.getFunction());
+ ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
+ if (!TLI)
+ return Changed;
+
+ if (TLI->getScalarMathLib() !=
+ TargetLibraryInfoImpl::ScalarLibrary::SCALAR_AMDLIBM) {
+ LLVM_DEBUG(dbgs() << "-scalar-library=AMDLIBM not used so bailing out.\n";);
+ return Changed;
+ }
+
+ for (auto *CI : Callsites) {
+ if (isCandidateSafeToLower(CI)) {
+ LLVM_DEBUG(dbgs() << "Call Inst has fastMath flags\n";);
+ Changed |= createScalarAOCLCall(CI);
+ } else
+ LLVM_DEBUG(dbgs() << "Call Inst does not have fastMath flags\n";);
+ }
+ return Changed;
+}
+
+char X86GenScalarAmdFastCalls::ID = 0;
+
+char &llvm::X86GenScalarAmdFastCallsID = X86GenScalarAmdFastCalls::ID;
+
+INITIALIZE_PASS_BEGIN(X86GenScalarAmdFastCalls, DEBUG_TYPE,
+ "Generate Scalar AMD Fast calls", false, false)
+INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
+INITIALIZE_PASS_END(X86GenScalarAmdFastCalls, DEBUG_TYPE,
+ "Generate Scalar AMD Fast calls", false, false)
+
+FunctionPass *llvm::createX86GenScalarAmdFastCallsPass() {
+ return new X86GenScalarAmdFastCalls();
+}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 886405a0c7baea..7063fce03dcf30 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -110,6 +110,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
initializeX86PreLegalizerCombinerLegacyPass(PR);
initializeX86PostLegalizerCombinerLegacyPass(PR);
initializeX86WinEHUnwindV3Pass(PR);
+ initializeX86GenScalarAmdFastCallsPass(PR);
}
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
@@ -535,6 +536,10 @@ void X86PassConfig::addPreRegAlloc() {
void X86PassConfig::addMachineSSAOptimization() {
addPass(createX86DomainReassignmentLegacyPass());
+ // Generate x86 target-specific function calls for scalar math functions
+ // that are available in the AMD AOCL library.
+ if (getOptLevel() == CodeGenOptLevel::Aggressive)
+ addPass(createX86GenScalarAmdFastCallsPass());
TargetPassConfig::addMachineSSAOptimization();
}
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
new file mode 100644
index 00000000000000..8cc4b1d9b94e2f
--- /dev/null
+++ b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
@@ -0,0 +1,31 @@
+; The AOCL fast-call lowering applies to 32-bit X86 (i686) as well as x86_64.
+
+; RUN: llc -mtriple=i686-unknown-linux-gnu -O3 -scalar-library=AMDLIBM < %s \
+; RUN: | FileCheck %s --check-prefix=AMD
+; RUN: llc -mtriple=i686-unknown-linux-gnu -O3 < %s \
+; RUN: | FileCheck %s --check-prefix=STD
+
+declare double @tan(double)
+declare float @expf(float)
+
+define double @call_tan(double %x) #0 {
+ %r = call double @tan(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_tan:
+; AMD: calll{{.*}}amd_fasttan
+; STD-LABEL: call_tan:
+; STD: calll{{.*}}tan
+
+define float @call_expf(float %x) #0 {
+ %r = call float @expf(float %x)
+ %a = fadd float %r, %x
+ ret float %a
+}
+; AMD-LABEL: call_expf:
+; AMD: calll{{.*}}amd_fastexpf
+; STD-LABEL: call_expf:
+; STD: calll{{.*}}expf
+
+attributes #0 = { "approx-func-fp-math"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" }
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
new file mode 100644
index 00000000000000..b98704409a0f3a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
@@ -0,0 +1,124 @@
+; Exercises the scalar->AOCL fast-call name mapping under fast-math at -O3 with
+; -scalar-library=AMDLIBM on X86: float variants, *_finite aliases and
+; inverse-trig functions are rewritten, while math calls with no AOCL mapping
+; (e.g. cbrt) are left untouched.
+
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -scalar-library=AMDLIBM < %s \
+; RUN: | FileCheck %s --check-prefix=AMD
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 < %s \
+; RUN: | FileCheck %s --check-prefix=STD
+
+declare float @tanf(float)
+declare float @powf(float, float)
+declare double @acos(double)
+declare float @acosf(float)
+declare double @atan(double)
+declare double @cos(double)
+declare float @sinf(float)
+declare double @erf(double)
+declare double @__exp_finite(double)
+declare double @pow(double, double)
+declare double @cbrt(double)
+
+; Single-precision variant: tanf -> amd_fasttanf
+define float @call_tanf(float %x) #0 {
+ %r = call float @tanf(float %x)
+ %a = fadd float %r, %x
+ ret float %a
+}
+; AMD-LABEL: call_tanf:
+; AMD: callq{{.*}}amd_fasttanf
+; STD-LABEL: call_tanf:
+; STD: callq{{.*}}tanf
+
+; Single-precision, two-argument variant: powf -> amd_fastpowf
+define float @call_powf(float %x, float %y) #0 {
+ %r = call float @powf(float %x, float %y)
+ %a = fadd float %r, %x
+ ret float %a
+}
+; AMD-LABEL: call_powf:
+; AMD: callq{{.*}}amd_fastpowf
+
+; Inverse-trigonometric functions.
+define double @call_acos(double %x) #0 {
+ %r = call double @acos(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_acos:
+; AMD: callq{{.*}}amd_fastacos
+
+define double @call_atan(double %x) #0 {
+ %r = call double @atan(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_atan:
+; AMD: callq{{.*}}amd_fastatan
+
+; Single-precision inverse-trig: acosf -> amd_fastacosf
+define float @call_acosf(float %x) #0 {
+ %r = call float @acosf(float %x)
+ %a = fadd float %r, %x
+ ret float %a
+}
+; AMD-LABEL: call_acosf:
+; AMD: callq{{.*}}amd_fastacosf
+
+; cos(double) -> amd_fastcos
+define double @call_cos(double %x) #0 {
+ %r = call double @cos(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_cos:
+; AMD: callq{{.*}}amd_fastcos
+
+; sinf -> amd_fastsinf
+define float @call_sinf(float %x) #0 {
+ %r = call float @sinf(float %x)
+ %a = fadd float %r, %x
+ ret float %a
+}
+; AMD-LABEL: call_sinf:
+; AMD: callq{{.*}}amd_fastsinf
+
+; erf(double) -> amd_fasterf
+define double @call_erf(double %x) #0 {
+ %r = call double @erf(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_erf:
+; AMD: callq{{.*}}amd_fasterf
+
+; pow(double) -> amd_fastpow
+define double @call_pow(double %x, double %y) #0 {
+ %r = call double @pow(double %x, double %y)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_pow:
+; AMD: callq{{.*}}amd_fastpow
+
+; A *_finite alias maps to the same fast entry as the base function.
+define double @call_exp_finite(double %x) #0 {
+ %r = call double @__exp_finite(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_exp_finite:
+; AMD: callq{{.*}}amd_fastexp
+
+; cbrt has no AOCL mapping and must not be rewritten.
+define double @call_cbrt_unmapped(double %x) #0 {
+ %r = call double @cbrt(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_cbrt_unmapped:
+; AMD-NOT: amd_fast
+; AMD: callq{{.*}}cbrt
+
+attributes #0 = { "approx-func-fp-math"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" }
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
new file mode 100644
index 00000000000000..96824158fe8530
--- /dev/null
+++ b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
@@ -0,0 +1,63 @@
+; Verify that, under fast-math at -O3 with -scalar-library=AMDLIBM, scalar math
+; library calls are rewritten to their AMD AOCL fast-call equivalents on X86,
+; and that they are left untouched without the option.
+
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -scalar-library=AMDLIBM < %s \
+; RUN: | FileCheck %s --check-prefix=AMD
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 < %s \
+; RUN: | FileCheck %s --check-prefix=STD
+
+declare double @tan(double)
+declare double @exp(double)
+declare double @log(double)
+
+define double @call_tan(double %x) #0 {
+entry:
+ %r = call double @tan(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+
+; AMD-LABEL: call_tan:
+; AMD: callq{{.*}}amd_fasttan
+; STD-LABEL: call_tan:
+; STD: callq{{.*}}tan
+
+define double @call_exp(double %x) #0 {
+entry:
+ %r = call double @exp(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+
+; AMD-LABEL: call_exp:
+; AMD: callq{{.*}}amd_fastexp
+; STD-LABEL: call_exp:
+; STD: callq{{.*}}exp
+
+define double @call_log(double %x) #0 {
+entry:
+ %r = call double @log(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+
+; AMD-LABEL: call_log:
+; AMD: callq{{.*}}amd_fastlog
+; STD-LABEL: call_log:
+; STD: callq{{.*}}log
+
+; Without the fast-math attributes the call must not be rewritten even when the
+; AMD scalar library is selected.
+define double @call_tan_no_fastmath(double %x) {
+entry:
+ %r = call double @tan(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+
+; AMD-LABEL: call_tan_no_fastmath:
+; AMD-NOT: amd_fasttan
+; AMD: callq{{.*}}tan
+
+attributes #0 = { "approx-func-fp-math"="true" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" }
diff --git a/llvm/test/CodeGen/X86/veclib-llvm.sincos.s b/llvm/test/CodeGen/X86/veclib-llvm.sincos.s
new file mode 100644
index 00000000000000..df1edb99dcd53a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/veclib-llvm.sincos.s
@@ -0,0 +1,258 @@
+ .att_syntax
+ .file "veclib-llvm.sincos.ll"
+ .text
+ .globl test_sincos_v4f32 # -- Begin function test_sincos_v4f32
+ .p2align 4
+ .type test_sincos_v4f32, at function
+test_sincos_v4f32: # @test_sincos_v4f32
+ .cfi_startproc
+# %bb.0:
+ pushq %rbx
+ .cfi_def_cfa_offset 16
+ subq $16, %rsp
+ .cfi_def_cfa_offset 32
+ .cfi_offset %rbx, -16
+ movq %rsi, %rbx
+ movq %rsp, %rsi
+ callq amd_vrs4_sincosf at PLT
+ movaps (%rsp), %xmm0
+ movaps %xmm0, (%rbx)
+ addq $16, %rsp
+ .cfi_def_cfa_offset 16
+ popq %rbx
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end0:
+ .size test_sincos_v4f32, .Lfunc_end0-test_sincos_v4f32
+ .cfi_endproc
+ # -- End function
+ .globl test_sincos_v8f32 # -- Begin function test_sincos_v8f32
+ .p2align 4
+ .type test_sincos_v8f32, at function
+test_sincos_v8f32: # @test_sincos_v8f32
+ .cfi_startproc
+# %bb.0:
+ pushq %r14
+ .cfi_def_cfa_offset 16
+ pushq %rbx
+ .cfi_def_cfa_offset 24
+ subq $56, %rsp
+ .cfi_def_cfa_offset 80
+ .cfi_offset %rbx, -24
+ .cfi_offset %r14, -16
+ movq %rsi, %rbx
+ movq %rdi, %r14
+ movaps %xmm0, (%rsp) # 16-byte Spill
+ addq $16, %rdi
+ leaq 16(%rsp), %rsi
+ movaps %xmm1, %xmm0
+ callq amd_vrs4_sincosf at PLT
+ leaq 32(%rsp), %rsi
+ movaps (%rsp), %xmm0 # 16-byte Reload
+ movq %r14, %rdi
+ callq amd_vrs4_sincosf at PLT
+ movaps 16(%rsp), %xmm0
+ movaps 32(%rsp), %xmm1
+ movaps %xmm1, (%rbx)
+ movaps %xmm0, 16(%rbx)
+ addq $56, %rsp
+ .cfi_def_cfa_offset 24
+ popq %rbx
+ .cfi_def_cfa_offset 16
+ popq %r14
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end1:
+ .size test_sincos_v8f32, .Lfunc_end1-test_sincos_v8f32
+ .cfi_endproc
+ # -- End function
+ .globl test_sincos_v16f32 # -- Begin function test_sincos_v16f32
+ .p2align 4
+ .type test_sincos_v16f32, at function
+test_sincos_v16f32: # @test_sincos_v16f32
+ .cfi_startproc
+# %bb.0:
+ pushq %r14
+ .cfi_def_cfa_offset 16
+ pushq %rbx
+ .cfi_def_cfa_offset 24
+ subq $120, %rsp
+ .cfi_def_cfa_offset 144
+ .cfi_offset %rbx, -24
+ .cfi_offset %r14, -16
+ movq %rsi, %rbx
+ movq %rdi, %r14
+ movaps %xmm3, (%rsp) # 16-byte Spill
+ movaps %xmm2, 16(%rsp) # 16-byte Spill
+ movaps %xmm0, 32(%rsp) # 16-byte Spill
+ addq $16, %rdi
+ leaq 80(%rsp), %rsi
+ movaps %xmm1, %xmm0
+ callq amd_vrs4_sincosf at PLT
+ leaq 48(%r14), %rdi
+ leaq 48(%rsp), %rsi
+ movaps (%rsp), %xmm0 # 16-byte Reload
+ callq amd_vrs4_sincosf at PLT
+ leaq 32(%r14), %rdi
+ leaq 64(%rsp), %rsi
+ movaps 16(%rsp), %xmm0 # 16-byte Reload
+ callq amd_vrs4_sincosf at PLT
+ leaq 96(%rsp), %rsi
+ movaps 32(%rsp), %xmm0 # 16-byte Reload
+ movq %r14, %rdi
+ callq amd_vrs4_sincosf at PLT
+ movaps 80(%rsp), %xmm0
+ movaps 48(%rsp), %xmm1
+ movaps 64(%rsp), %xmm2
+ movaps 96(%rsp), %xmm3
+ movaps %xmm3, (%rbx)
+ movaps %xmm2, 32(%rbx)
+ movaps %xmm1, 48(%rbx)
+ movaps %xmm0, 16(%rbx)
+ addq $120, %rsp
+ .cfi_def_cfa_offset 24
+ popq %rbx
+ .cfi_def_cfa_offset 16
+ popq %r14
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end2:
+ .size test_sincos_v16f32, .Lfunc_end2-test_sincos_v16f32
+ .cfi_endproc
+ # -- End function
+ .globl test_sincos_v2f64 # -- Begin function test_sincos_v2f64
+ .p2align 4
+ .type test_sincos_v2f64, at function
+test_sincos_v2f64: # @test_sincos_v2f64
+ .cfi_startproc
+# %bb.0:
+ pushq %rbx
+ .cfi_def_cfa_offset 16
+ subq $16, %rsp
+ .cfi_def_cfa_offset 32
+ .cfi_offset %rbx, -16
+ movq %rsi, %rbx
+ movq %rsp, %rsi
+ callq amd_vrd2_sincos at PLT
+ movaps (%rsp), %xmm0
+ movaps %xmm0, (%rbx)
+ addq $16, %rsp
+ .cfi_def_cfa_offset 16
+ popq %rbx
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end3:
+ .size test_sincos_v2f64, .Lfunc_end3-test_sincos_v2f64
+ .cfi_endproc
+ # -- End function
+ .globl test_sincos_v4f64 # -- Begin function test_sincos_v4f64
+ .p2align 4
+ .type test_sincos_v4f64, at function
+test_sincos_v4f64: # @test_sincos_v4f64
+ .cfi_startproc
+# %bb.0:
+ pushq %r14
+ .cfi_def_cfa_offset 16
+ pushq %rbx
+ .cfi_def_cfa_offset 24
+ subq $56, %rsp
+ .cfi_def_cfa_offset 80
+ .cfi_offset %rbx, -24
+ .cfi_offset %r14, -16
+ movq %rsi, %rbx
+ movq %rdi, %r14
+ movaps %xmm0, (%rsp) # 16-byte Spill
+ addq $16, %rdi
+ leaq 16(%rsp), %rsi
+ movaps %xmm1, %xmm0
+ callq amd_vrd2_sincos at PLT
+ leaq 32(%rsp), %rsi
+ movaps (%rsp), %xmm0 # 16-byte Reload
+ movq %r14, %rdi
+ callq amd_vrd2_sincos at PLT
+ movaps 16(%rsp), %xmm0
+ movaps 32(%rsp), %xmm1
+ movaps %xmm1, (%rbx)
+ movaps %xmm0, 16(%rbx)
+ addq $56, %rsp
+ .cfi_def_cfa_offset 24
+ popq %rbx
+ .cfi_def_cfa_offset 16
+ popq %r14
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end4:
+ .size test_sincos_v4f64, .Lfunc_end4-test_sincos_v4f64
+ .cfi_endproc
+ # -- End function
+ .globl test_sincos_v8f64 # -- Begin function test_sincos_v8f64
+ .p2align 4
+ .type test_sincos_v8f64, at function
+test_sincos_v8f64: # @test_sincos_v8f64
+ .cfi_startproc
+# %bb.0:
+ pushq %r14
+ .cfi_def_cfa_offset 16
+ pushq %rbx
+ .cfi_def_cfa_offset 24
+ subq $120, %rsp
+ .cfi_def_cfa_offset 144
+ .cfi_offset %rbx, -24
+ .cfi_offset %r14, -16
+ movq %rsi, %rbx
+ movq %rdi, %r14
+ movaps %xmm3, (%rsp) # 16-byte Spill
+ movaps %xmm2, 16(%rsp) # 16-byte Spill
+ movaps %xmm0, 32(%rsp) # 16-byte Spill
+ addq $16, %rdi
+ leaq 80(%rsp), %rsi
+ movaps %xmm1, %xmm0
+ callq amd_vrd2_sincos at PLT
+ leaq 48(%r14), %rdi
+ leaq 48(%rsp), %rsi
+ movaps (%rsp), %xmm0 # 16-byte Reload
+ callq amd_vrd2_sincos at PLT
+ leaq 32(%r14), %rdi
+ leaq 64(%rsp), %rsi
+ movaps 16(%rsp), %xmm0 # 16-byte Reload
+ callq amd_vrd2_sincos at PLT
+ leaq 96(%rsp), %rsi
+ movaps 32(%rsp), %xmm0 # 16-byte Reload
+ movq %r14, %rdi
+ callq amd_vrd2_sincos at PLT
+ movaps 80(%rsp), %xmm0
+ movaps 48(%rsp), %xmm1
+ movaps 64(%rsp), %xmm2
+ movaps 96(%rsp), %xmm3
+ movaps %xmm3, (%rbx)
+ movaps %xmm2, 32(%rbx)
+ movaps %xmm1, 48(%rbx)
+ movaps %xmm0, 16(%rbx)
+ addq $120, %rsp
+ .cfi_def_cfa_offset 24
+ popq %rbx
+ .cfi_def_cfa_offset 16
+ popq %r14
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end5:
+ .size test_sincos_v8f64, .Lfunc_end5-test_sincos_v8f64
+ .cfi_endproc
+ # -- End function
+ .globl test_sincos_v4f32_void # -- Begin function test_sincos_v4f32_void
+ .p2align 4
+ .type test_sincos_v4f32_void, at function
+test_sincos_v4f32_void: # @test_sincos_v4f32_void
+ .cfi_startproc
+# %bb.0:
+ pushq %rax
+ .cfi_def_cfa_offset 16
+ callq sincosf at PLT
+ popq %rax
+ .cfi_def_cfa_offset 8
+ retq
+.Lfunc_end6:
+ .size test_sincos_v4f32_void, .Lfunc_end6-test_sincos_v4f32_void
+ .cfi_endproc
+ # -- End function
+ .section ".note.GNU-stack","", at progbits
>From 9dd8217b146177ec414a2e52822fe5f7a02d50c2 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Mon, 3 Aug 2026 19:29:32 +0530
Subject: [PATCH 02/10] Fix the formatting issue.
---
llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp b/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
index 85544a2436c730..0a4b1b7b32cd21 100644
--- a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
+++ b/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
@@ -107,8 +107,8 @@ bool X86GenScalarAmdFastCalls::createScalarAOCLCall(MachineInstr *MI) const {
MI->getOperand(0).ChangeToES(LibScalarFnName.data(),
MI->getOperand(0).getTargetFlags());
- LLVM_DEBUG(dbgs() << "Successfully replaced with fastcall= " << LibScalarFnName
- << "\n";);
+ LLVM_DEBUG(dbgs() << "Successfully replaced with fastcall= "
+ << LibScalarFnName << "\n";);
ORE->emit([&]() {
return MachineOptimizationRemark(DEBUG_TYPE, "Passed", MI->getDebugLoc(),
>From 64f6303298db527f5121a8d1585fb2cd4c662c04 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Tue, 4 Aug 2026 14:05:23 +0530
Subject: [PATCH 03/10] Fix the test cases failure
---
llvm/test/CodeGen/X86/opt-pipeline.ll | 5 +-
llvm/test/CodeGen/X86/veclib-llvm.sincos.s | 258 ---------------------
2 files changed, 4 insertions(+), 259 deletions(-)
delete mode 100644 llvm/test/CodeGen/X86/veclib-llvm.sincos.s
diff --git a/llvm/test/CodeGen/X86/opt-pipeline.ll b/llvm/test/CodeGen/X86/opt-pipeline.ll
index e0256b66fff893..d33f07f903e3a1 100644
--- a/llvm/test/CodeGen/X86/opt-pipeline.ll
+++ b/llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -5,7 +5,7 @@
; RUN: llc -mtriple=x86_64-- -O2 -debug-pass=Structure < %s -o /dev/null 2>&1 \
; RUN: | grep -v 'Verify generated machine code' | FileCheck %s
; RUN: llc -mtriple=x86_64-- -O3 -debug-pass=Structure < %s -o /dev/null 2>&1 \
-; RUN: | grep -v 'Verify generated machine code' | FileCheck %s
+; RUN: | grep -v 'Verify generated machine code' | FileCheck %s --check-prefixes=CHECK,O3
; RUN: llc -mtriple=x86_64-- -O3 -debug-pass=Structure < %s -o /dev/null 2>&1 \
; RUN: | FileCheck %s --check-prefix=FPM
@@ -95,6 +95,9 @@
; CHECK-NEXT: Finalize ISel and expand pseudo-instructions
; CHECK-NEXT: X86 Domain Reassignment Pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; O3-NEXT: Machine Optimization Remark Emitter
+; O3-NEXT: X86 Generate Scalar AOCL Entries
+; O3-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Early Tail Duplication
; CHECK-NEXT: Optimize machine instruction PHIs
; CHECK-NEXT: Slot index numbering
diff --git a/llvm/test/CodeGen/X86/veclib-llvm.sincos.s b/llvm/test/CodeGen/X86/veclib-llvm.sincos.s
deleted file mode 100644
index df1edb99dcd53a..00000000000000
--- a/llvm/test/CodeGen/X86/veclib-llvm.sincos.s
+++ /dev/null
@@ -1,258 +0,0 @@
- .att_syntax
- .file "veclib-llvm.sincos.ll"
- .text
- .globl test_sincos_v4f32 # -- Begin function test_sincos_v4f32
- .p2align 4
- .type test_sincos_v4f32, at function
-test_sincos_v4f32: # @test_sincos_v4f32
- .cfi_startproc
-# %bb.0:
- pushq %rbx
- .cfi_def_cfa_offset 16
- subq $16, %rsp
- .cfi_def_cfa_offset 32
- .cfi_offset %rbx, -16
- movq %rsi, %rbx
- movq %rsp, %rsi
- callq amd_vrs4_sincosf at PLT
- movaps (%rsp), %xmm0
- movaps %xmm0, (%rbx)
- addq $16, %rsp
- .cfi_def_cfa_offset 16
- popq %rbx
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end0:
- .size test_sincos_v4f32, .Lfunc_end0-test_sincos_v4f32
- .cfi_endproc
- # -- End function
- .globl test_sincos_v8f32 # -- Begin function test_sincos_v8f32
- .p2align 4
- .type test_sincos_v8f32, at function
-test_sincos_v8f32: # @test_sincos_v8f32
- .cfi_startproc
-# %bb.0:
- pushq %r14
- .cfi_def_cfa_offset 16
- pushq %rbx
- .cfi_def_cfa_offset 24
- subq $56, %rsp
- .cfi_def_cfa_offset 80
- .cfi_offset %rbx, -24
- .cfi_offset %r14, -16
- movq %rsi, %rbx
- movq %rdi, %r14
- movaps %xmm0, (%rsp) # 16-byte Spill
- addq $16, %rdi
- leaq 16(%rsp), %rsi
- movaps %xmm1, %xmm0
- callq amd_vrs4_sincosf at PLT
- leaq 32(%rsp), %rsi
- movaps (%rsp), %xmm0 # 16-byte Reload
- movq %r14, %rdi
- callq amd_vrs4_sincosf at PLT
- movaps 16(%rsp), %xmm0
- movaps 32(%rsp), %xmm1
- movaps %xmm1, (%rbx)
- movaps %xmm0, 16(%rbx)
- addq $56, %rsp
- .cfi_def_cfa_offset 24
- popq %rbx
- .cfi_def_cfa_offset 16
- popq %r14
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end1:
- .size test_sincos_v8f32, .Lfunc_end1-test_sincos_v8f32
- .cfi_endproc
- # -- End function
- .globl test_sincos_v16f32 # -- Begin function test_sincos_v16f32
- .p2align 4
- .type test_sincos_v16f32, at function
-test_sincos_v16f32: # @test_sincos_v16f32
- .cfi_startproc
-# %bb.0:
- pushq %r14
- .cfi_def_cfa_offset 16
- pushq %rbx
- .cfi_def_cfa_offset 24
- subq $120, %rsp
- .cfi_def_cfa_offset 144
- .cfi_offset %rbx, -24
- .cfi_offset %r14, -16
- movq %rsi, %rbx
- movq %rdi, %r14
- movaps %xmm3, (%rsp) # 16-byte Spill
- movaps %xmm2, 16(%rsp) # 16-byte Spill
- movaps %xmm0, 32(%rsp) # 16-byte Spill
- addq $16, %rdi
- leaq 80(%rsp), %rsi
- movaps %xmm1, %xmm0
- callq amd_vrs4_sincosf at PLT
- leaq 48(%r14), %rdi
- leaq 48(%rsp), %rsi
- movaps (%rsp), %xmm0 # 16-byte Reload
- callq amd_vrs4_sincosf at PLT
- leaq 32(%r14), %rdi
- leaq 64(%rsp), %rsi
- movaps 16(%rsp), %xmm0 # 16-byte Reload
- callq amd_vrs4_sincosf at PLT
- leaq 96(%rsp), %rsi
- movaps 32(%rsp), %xmm0 # 16-byte Reload
- movq %r14, %rdi
- callq amd_vrs4_sincosf at PLT
- movaps 80(%rsp), %xmm0
- movaps 48(%rsp), %xmm1
- movaps 64(%rsp), %xmm2
- movaps 96(%rsp), %xmm3
- movaps %xmm3, (%rbx)
- movaps %xmm2, 32(%rbx)
- movaps %xmm1, 48(%rbx)
- movaps %xmm0, 16(%rbx)
- addq $120, %rsp
- .cfi_def_cfa_offset 24
- popq %rbx
- .cfi_def_cfa_offset 16
- popq %r14
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end2:
- .size test_sincos_v16f32, .Lfunc_end2-test_sincos_v16f32
- .cfi_endproc
- # -- End function
- .globl test_sincos_v2f64 # -- Begin function test_sincos_v2f64
- .p2align 4
- .type test_sincos_v2f64, at function
-test_sincos_v2f64: # @test_sincos_v2f64
- .cfi_startproc
-# %bb.0:
- pushq %rbx
- .cfi_def_cfa_offset 16
- subq $16, %rsp
- .cfi_def_cfa_offset 32
- .cfi_offset %rbx, -16
- movq %rsi, %rbx
- movq %rsp, %rsi
- callq amd_vrd2_sincos at PLT
- movaps (%rsp), %xmm0
- movaps %xmm0, (%rbx)
- addq $16, %rsp
- .cfi_def_cfa_offset 16
- popq %rbx
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end3:
- .size test_sincos_v2f64, .Lfunc_end3-test_sincos_v2f64
- .cfi_endproc
- # -- End function
- .globl test_sincos_v4f64 # -- Begin function test_sincos_v4f64
- .p2align 4
- .type test_sincos_v4f64, at function
-test_sincos_v4f64: # @test_sincos_v4f64
- .cfi_startproc
-# %bb.0:
- pushq %r14
- .cfi_def_cfa_offset 16
- pushq %rbx
- .cfi_def_cfa_offset 24
- subq $56, %rsp
- .cfi_def_cfa_offset 80
- .cfi_offset %rbx, -24
- .cfi_offset %r14, -16
- movq %rsi, %rbx
- movq %rdi, %r14
- movaps %xmm0, (%rsp) # 16-byte Spill
- addq $16, %rdi
- leaq 16(%rsp), %rsi
- movaps %xmm1, %xmm0
- callq amd_vrd2_sincos at PLT
- leaq 32(%rsp), %rsi
- movaps (%rsp), %xmm0 # 16-byte Reload
- movq %r14, %rdi
- callq amd_vrd2_sincos at PLT
- movaps 16(%rsp), %xmm0
- movaps 32(%rsp), %xmm1
- movaps %xmm1, (%rbx)
- movaps %xmm0, 16(%rbx)
- addq $56, %rsp
- .cfi_def_cfa_offset 24
- popq %rbx
- .cfi_def_cfa_offset 16
- popq %r14
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end4:
- .size test_sincos_v4f64, .Lfunc_end4-test_sincos_v4f64
- .cfi_endproc
- # -- End function
- .globl test_sincos_v8f64 # -- Begin function test_sincos_v8f64
- .p2align 4
- .type test_sincos_v8f64, at function
-test_sincos_v8f64: # @test_sincos_v8f64
- .cfi_startproc
-# %bb.0:
- pushq %r14
- .cfi_def_cfa_offset 16
- pushq %rbx
- .cfi_def_cfa_offset 24
- subq $120, %rsp
- .cfi_def_cfa_offset 144
- .cfi_offset %rbx, -24
- .cfi_offset %r14, -16
- movq %rsi, %rbx
- movq %rdi, %r14
- movaps %xmm3, (%rsp) # 16-byte Spill
- movaps %xmm2, 16(%rsp) # 16-byte Spill
- movaps %xmm0, 32(%rsp) # 16-byte Spill
- addq $16, %rdi
- leaq 80(%rsp), %rsi
- movaps %xmm1, %xmm0
- callq amd_vrd2_sincos at PLT
- leaq 48(%r14), %rdi
- leaq 48(%rsp), %rsi
- movaps (%rsp), %xmm0 # 16-byte Reload
- callq amd_vrd2_sincos at PLT
- leaq 32(%r14), %rdi
- leaq 64(%rsp), %rsi
- movaps 16(%rsp), %xmm0 # 16-byte Reload
- callq amd_vrd2_sincos at PLT
- leaq 96(%rsp), %rsi
- movaps 32(%rsp), %xmm0 # 16-byte Reload
- movq %r14, %rdi
- callq amd_vrd2_sincos at PLT
- movaps 80(%rsp), %xmm0
- movaps 48(%rsp), %xmm1
- movaps 64(%rsp), %xmm2
- movaps 96(%rsp), %xmm3
- movaps %xmm3, (%rbx)
- movaps %xmm2, 32(%rbx)
- movaps %xmm1, 48(%rbx)
- movaps %xmm0, 16(%rbx)
- addq $120, %rsp
- .cfi_def_cfa_offset 24
- popq %rbx
- .cfi_def_cfa_offset 16
- popq %r14
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end5:
- .size test_sincos_v8f64, .Lfunc_end5-test_sincos_v8f64
- .cfi_endproc
- # -- End function
- .globl test_sincos_v4f32_void # -- Begin function test_sincos_v4f32_void
- .p2align 4
- .type test_sincos_v4f32_void, at function
-test_sincos_v4f32_void: # @test_sincos_v4f32_void
- .cfi_startproc
-# %bb.0:
- pushq %rax
- .cfi_def_cfa_offset 16
- callq sincosf at PLT
- popq %rax
- .cfi_def_cfa_offset 8
- retq
-.Lfunc_end6:
- .size test_sincos_v4f32_void, .Lfunc_end6-test_sincos_v4f32_void
- .cfi_endproc
- # -- End function
- .section ".note.GNU-stack","", at progbits
>From 583e91932e61e21437d226a77b3bc2a1452746f2 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Fri, 21 Aug 2026 00:27:42 +0530
Subject: [PATCH 04/10] Change the name of option sclrlib to fastlib
---
clang/include/clang/Basic/CodeGenOptions.h | 2 +-
clang/include/clang/Options/Options.td | 4 ++--
clang/lib/CodeGen/BackendUtil.cpp | 2 +-
clang/lib/Driver/ToolChains/CommonArgs.cpp | 2 +-
clang/test/CodeGen/X86/aocl-fast-scalar-calls.c | 4 ++--
llvm/lib/Analysis/TargetLibraryInfo.cpp | 2 +-
llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp | 8 ++++----
llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll | 2 +-
llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll | 4 ++--
llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll | 4 ++--
10 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 43d45d0261f211..33e3fecc7f19dd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -110,7 +110,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
OnlyAlwaysInlining // Only run the always inlining pass.
};
- /// Scalar math functions library to use with -fsclrlib=.
+ /// Fast math functions library to use with -ffastlib=.
enum ScalarLibrary {
Default_Scalar_Library, // Use default library.
SCALAR_AMDLIBM // AMD scalar math library.
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 675ada8a49458f..97031e1df4a41a 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4025,9 +4025,9 @@ def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>,
NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "SLEEF",
"Darwin_libsystem_m", "ArmPL", "AMDLIBM", "NoLibrary"]>,
MarshallingInfoEnum<CodeGenOpts<"VecLib">, "NoLibrary">;
-def fsclrlib : Joined<["-"], "fsclrlib=">, Group<f_Group>,
+def fsclrlib : Joined<["-"], "ffastlib=">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
- HelpText<"Use the given scalar math functions library.">,
+ HelpText<"Use the given fast math functions library.">,
Values<"AMDLIBM,none">,
NormalizedValuesScope<"CodeGenOptions">,
NormalizedValues<["SCALAR_AMDLIBM", "Default_Scalar_Library"]>,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 439b0461d35b58..b6bbf7c0a75414 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -147,7 +147,7 @@ static std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
}
/// Populate the scalar math library mappings on \p TLII according to the
-/// -fsclrlib= selection.
+/// -ffastlib= selection.
static void addScalarMathLibrary(TargetLibraryInfoImpl &TLII,
const CodeGenOptions &CodeGenOpts) {
switch (CodeGenOpts.getScalarLib()) {
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 727ea9babff7f4..960e9fae18de8f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1159,7 +1159,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
StringRef Name = ArgScalarLib->getValue();
if (Name == "AMDLIBM")
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
- "-scalar-library=" + Name));
+ "-fast-library=" + Name));
}
// Try to pass driver level flags relevant to LTO code generation down to
diff --git a/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c b/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
index 50a512ebc2a5ed..e0e933a7cde0e9 100644
--- a/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
+++ b/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
@@ -1,11 +1,11 @@
-// Verify that the -fsclrlib=AMDLIBM driver flag, together with fast-math at -O3,
+// Verify that the -ffastlib=AMDLIBM driver flag, together with fast-math at -O3,
// rewrites scalar math library calls into their AMD AOCL fast-call equivalents
// for X86, and leaves them untouched without the flag.
// REQUIRES: x86-registered-target
// RUN: %clang --target=x86_64-unknown-linux-gnu -O3 -ffast-math \
-// RUN: -fsclrlib=AMDLIBM -S %s -o - | FileCheck %s --check-prefix=AMD
+// RUN: -ffastlib=AMDLIBM -S %s -o - | FileCheck %s --check-prefix=AMD
// RUN: %clang --target=x86_64-unknown-linux-gnu -O3 -ffast-math \
// RUN: -S %s -o - | FileCheck %s --check-prefix=STD
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 3481c5e5562821..7c9313b7089b09 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -23,7 +23,7 @@
using namespace llvm;
static cl::opt<TargetLibraryInfoImpl::ScalarLibrary> ClScalarLibrary(
- "scalar-library", cl::Hidden, cl::desc("Scalar functions library"),
+ "fast-library", cl::Hidden, cl::desc("fast functions library"),
cl::init(TargetLibraryInfoImpl::Default_Scalar_Library),
cl::values(clEnumValN(TargetLibraryInfoImpl::Default_Scalar_Library, "none",
"Use default library"),
diff --git a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp b/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
index 0a4b1b7b32cd21..1e89ecccf56a19 100644
--- a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
+++ b/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
@@ -10,8 +10,8 @@
// corresponding AMD AOCL scalar library entries for X86 targets, e.g.:
// tan ---> amd_fasttan
// Such lowering is only legal under fast-math semantics and when the AMD
-// scalar math library has been selected (-scalar-library=AMDLIBM /
-// -fsclrlib=AMDLIBM).
+// fast math library has been selected (-fast-library=AMDLIBM /
+// -ffastlib=AMDLIBM).
//
//===----------------------------------------------------------------------===//
@@ -72,7 +72,7 @@ class X86GenScalarAmdFastCalls : public MachineFunctionPass {
// per-operation fast-math flags carried by the original call have already been
// lowered away, so we rely on the function-level fast-math attribute that the
// frontend sets under -ffast-math. Together with the explicit
-// -scalar-library=AMDLIBM opt-in (checked in runOnMachineFunction) this gates
+// -fast-library=AMDLIBM opt-in (checked in runOnMachineFunction) this gates
// the transformation.
bool X86GenScalarAmdFastCalls::isCandidateSafeToLower(MachineInstr *MI) const {
const Function &F = MI->getMF()->getFunction();
@@ -146,7 +146,7 @@ bool X86GenScalarAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
if (TLI->getScalarMathLib() !=
TargetLibraryInfoImpl::ScalarLibrary::SCALAR_AMDLIBM) {
- LLVM_DEBUG(dbgs() << "-scalar-library=AMDLIBM not used so bailing out.\n";);
+ LLVM_DEBUG(dbgs() << "-fast-library=AMDLIBM not used so bailing out.\n";);
return Changed;
}
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
index 8cc4b1d9b94e2f..9025ae01096957 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
+++ b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
@@ -1,6 +1,6 @@
; The AOCL fast-call lowering applies to 32-bit X86 (i686) as well as x86_64.
-; RUN: llc -mtriple=i686-unknown-linux-gnu -O3 -scalar-library=AMDLIBM < %s \
+; RUN: llc -mtriple=i686-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
; RUN: llc -mtriple=i686-unknown-linux-gnu -O3 < %s \
; RUN: | FileCheck %s --check-prefix=STD
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
index b98704409a0f3a..64ddcedd0ce61d 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
+++ b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
@@ -1,9 +1,9 @@
; Exercises the scalar->AOCL fast-call name mapping under fast-math at -O3 with
-; -scalar-library=AMDLIBM on X86: float variants, *_finite aliases and
+; -fast-library=AMDLIBM on X86: float variants, *_finite aliases and
; inverse-trig functions are rewritten, while math calls with no AOCL mapping
; (e.g. cbrt) are left untouched.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -scalar-library=AMDLIBM < %s \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 < %s \
; RUN: | FileCheck %s --check-prefix=STD
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
index 96824158fe8530..63947c1dd44583 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
+++ b/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
@@ -1,8 +1,8 @@
-; Verify that, under fast-math at -O3 with -scalar-library=AMDLIBM, scalar math
+; Verify that, under fast-math at -O3 with -fast-library=AMDLIBM, scalar math
; library calls are rewritten to their AMD AOCL fast-call equivalents on X86,
; and that they are left untouched without the option.
-; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -scalar-library=AMDLIBM < %s \
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 < %s \
; RUN: | FileCheck %s --check-prefix=STD
>From ef69d76723d5bad6507a6ed695353d7e0cda02ba Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Fri, 21 Aug 2026 01:34:24 +0530
Subject: [PATCH 05/10] Fix the formatting issue.
---
clang/lib/Driver/ToolChains/CommonArgs.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 960e9fae18de8f..03855be4c97589 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1158,8 +1158,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
if (Arg *ArgScalarLib = Args.getLastArg(options::OPT_fsclrlib)) {
StringRef Name = ArgScalarLib->getValue();
if (Name == "AMDLIBM")
- CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
- "-fast-library=" + Name));
+ CmdArgs.push_back(
+ Args.MakeArgString(Twine(PluginOptPrefix) + "-fast-library=" + Name));
}
// Try to pass driver level flags relevant to LTO code generation down to
>From 0f4b3c09551bc8a7d0579f521d4014b2e4e9b642 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Fri, 21 Aug 2026 01:57:31 +0530
Subject: [PATCH 06/10] Refactor fsclrlib/Scalar* identifiers to ffastlib/Fast*
Rename internal fsclrlib/Scalar* identifiers to ffastlib/Fast* across clang, LLVM TLI, the X86 pass, and tests. All 5 lit tests pass.
---
clang/include/clang/Basic/CodeGenOptions.def | 4 +-
clang/include/clang/Basic/CodeGenOptions.h | 6 +-
clang/include/clang/Options/Options.td | 6 +-
clang/lib/CodeGen/BackendUtil.cpp | 16 ++--
clang/lib/Driver/ToolChains/Clang.cpp | 2 +-
clang/lib/Driver/ToolChains/CommonArgs.cpp | 6 +-
...-fast-scalar-calls.c => aocl-fast-calls.c} | 4 +-
llvm/include/llvm/Analysis/FastAOCLFuncs.def | 80 +++++++++++++++++++
.../include/llvm/Analysis/ScalarAOCLFuncs.def | 80 -------------------
.../include/llvm/Analysis/TargetLibraryInfo.h | 46 +++++------
llvm/lib/Analysis/TargetLibraryInfo.cpp | 66 +++++++--------
llvm/lib/Target/X86/CMakeLists.txt | 2 +-
llvm/lib/Target/X86/X86.h | 8 +-
...mdFastCalls.cpp => X86GenAmdFastCalls.cpp} | 64 +++++++--------
llvm/lib/Target/X86/X86TargetMachine.cpp | 8 +-
...-calls-i686.ll => aocl-fast-calls-i686.ll} | 0
...appings.ll => aocl-fast-calls-mappings.ll} | 4 +-
...ast-scalar-calls.ll => aocl-fast-calls.ll} | 8 +-
llvm/test/CodeGen/X86/opt-pipeline.ll | 2 +-
19 files changed, 206 insertions(+), 206 deletions(-)
rename clang/test/CodeGen/X86/{aocl-fast-scalar-calls.c => aocl-fast-calls.c} (89%)
create mode 100644 llvm/include/llvm/Analysis/FastAOCLFuncs.def
delete mode 100644 llvm/include/llvm/Analysis/ScalarAOCLFuncs.def
rename llvm/lib/Target/X86/{X86GenScalarAmdFastCalls.cpp => X86GenAmdFastCalls.cpp} (69%)
rename llvm/test/CodeGen/X86/{aocl-fast-scalar-calls-i686.ll => aocl-fast-calls-i686.ll} (100%)
rename llvm/test/CodeGen/X86/{aocl-fast-scalar-calls-mappings.ll => aocl-fast-calls-mappings.ll} (95%)
rename llvm/test/CodeGen/X86/{aocl-fast-scalar-calls.ll => aocl-fast-calls.ll} (89%)
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index d76727f70ab439..74d89fa0e0d5c1 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -419,8 +419,8 @@ VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX, Benign)
// Vector functions library to use.
ENUM_CODEGENOPT(VecLib, VectorLibrary, 4, VectorLibrary::NoLibrary, Benign)
-// Scalar math functions library to use.
-ENUM_CODEGENOPT(ScalarLib, ScalarLibrary, 1, Default_Scalar_Library, Benign)
+// Fast math functions library to use.
+ENUM_CODEGENOPT(FastLib, FastLibrary, 1, NoFastLibrary, Benign)
/// The default TLS model to use.
ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel, Benign)
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 33e3fecc7f19dd..91062c654777fc 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -111,9 +111,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
};
/// Fast math functions library to use with -ffastlib=.
- enum ScalarLibrary {
- Default_Scalar_Library, // Use default library.
- SCALAR_AMDLIBM // AMD scalar math library.
+ enum FastLibrary {
+ NoFastLibrary, // Use default library.
+ FAST_AMDLIBM // AMD fast math library.
};
enum ObjCDispatchMethodKind {
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 97031e1df4a41a..c2a461c753fc59 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4025,13 +4025,13 @@ def fveclib : Joined<["-"], "fveclib=">, Group<f_Group>,
NormalizedValues<["Accelerate", "LIBMVEC", "MASSV", "SVML", "SLEEF",
"Darwin_libsystem_m", "ArmPL", "AMDLIBM", "NoLibrary"]>,
MarshallingInfoEnum<CodeGenOpts<"VecLib">, "NoLibrary">;
-def fsclrlib : Joined<["-"], "ffastlib=">, Group<f_Group>,
+def ffastlib : Joined<["-"], "ffastlib=">, Group<f_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Use the given fast math functions library.">,
Values<"AMDLIBM,none">,
NormalizedValuesScope<"CodeGenOptions">,
- NormalizedValues<["SCALAR_AMDLIBM", "Default_Scalar_Library"]>,
- MarshallingInfoEnum<CodeGenOpts<"ScalarLib">, "Default_Scalar_Library">;
+ NormalizedValues<["FAST_AMDLIBM", "NoFastLibrary"]>,
+ MarshallingInfoEnum<CodeGenOpts<"FastLib">, "NoFastLibrary">;
def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>,
Alias<flax_vector_conversions_EQ>, AliasArgs<["none"]>;
def fno_implicit_module_maps : Flag <["-"], "fno-implicit-module-maps">, Group<f_Group>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index b6bbf7c0a75414..70e6386c18fb46 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -146,15 +146,15 @@ static std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
return FileName;
}
-/// Populate the scalar math library mappings on \p TLII according to the
+/// Populate the fast math library mappings on \p TLII according to the
/// -ffastlib= selection.
-static void addScalarMathLibrary(TargetLibraryInfoImpl &TLII,
- const CodeGenOptions &CodeGenOpts) {
- switch (CodeGenOpts.getScalarLib()) {
- case CodeGenOptions::SCALAR_AMDLIBM:
- TLII.addScalarFunctionsFromMathLib(TargetLibraryInfoImpl::SCALAR_AMDLIBM);
+static void addFastMathLibrary(TargetLibraryInfoImpl &TLII,
+ const CodeGenOptions &CodeGenOpts) {
+ switch (CodeGenOpts.getFastLib()) {
+ case CodeGenOptions::FAST_AMDLIBM:
+ TLII.addFastFunctionsFromMathLib(TargetLibraryInfoImpl::FAST_AMDLIBM);
break;
- case CodeGenOptions::Default_Scalar_Library:
+ case CodeGenOptions::NoFastLibrary:
break;
}
}
@@ -1002,7 +1002,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
// preset TLI.
std::unique_ptr<TargetLibraryInfoImpl> TLII(
llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
- addScalarMathLibrary(*TLII, CodeGenOpts);
+ addFastMathLibrary(*TLII, CodeGenOpts);
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
// Register all the basic analyses with the managers.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 7bc4cccf3c8090..bc71a08332df46 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6035,7 +6035,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
A->render(Args, CmdArgs);
}
- if (Arg *A = Args.getLastArg(options::OPT_fsclrlib)) {
+ if (Arg *A = Args.getLastArg(options::OPT_ffastlib)) {
StringRef Name = A->getValue();
if (Name == "AMDLIBM") {
if (Triple.getArch() != llvm::Triple::x86 &&
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 03855be4c97589..74edecc6c921be 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1154,9 +1154,9 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
}
- // Pass scalar math library arguments to LTO.
- if (Arg *ArgScalarLib = Args.getLastArg(options::OPT_fsclrlib)) {
- StringRef Name = ArgScalarLib->getValue();
+ // Pass fast math library arguments to LTO.
+ if (Arg *ArgFastLib = Args.getLastArg(options::OPT_ffastlib)) {
+ StringRef Name = ArgFastLib->getValue();
if (Name == "AMDLIBM")
CmdArgs.push_back(
Args.MakeArgString(Twine(PluginOptPrefix) + "-fast-library=" + Name));
diff --git a/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c b/clang/test/CodeGen/X86/aocl-fast-calls.c
similarity index 89%
rename from clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
rename to clang/test/CodeGen/X86/aocl-fast-calls.c
index e0e933a7cde0e9..afd53369d64e97 100644
--- a/clang/test/CodeGen/X86/aocl-fast-scalar-calls.c
+++ b/clang/test/CodeGen/X86/aocl-fast-calls.c
@@ -1,6 +1,6 @@
// Verify that the -ffastlib=AMDLIBM driver flag, together with fast-math at -O3,
-// rewrites scalar math library calls into their AMD AOCL fast-call equivalents
-// for X86, and leaves them untouched without the flag.
+// rewrites math library calls into their AMD AOCL fast-call equivalents for X86,
+// and leaves them untouched without the flag.
// REQUIRES: x86-registered-target
diff --git a/llvm/include/llvm/Analysis/FastAOCLFuncs.def b/llvm/include/llvm/Analysis/FastAOCLFuncs.def
new file mode 100644
index 00000000000000..358ca17f301ae8
--- /dev/null
+++ b/llvm/include/llvm/Analysis/FastAOCLFuncs.def
@@ -0,0 +1,80 @@
+//===-- FastAOCLFuncs.def - AMD fast math library mappings ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This .def file creates a mapping from standard math functions to their
+// corresponding fast entry points in the AMD AOCL fast math library. The
+// lowering is only legal under fast-math semantics.
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(TLI_DEFINE_FAST_AOCL_FUNCS)
+#define TLI_DEFINE_FAST_AOCL_FUNC(SCAL, AOCLENTRY) {SCAL, AOCLENTRY},
+
+TLI_DEFINE_FAST_AOCL_FUNC("acosf", "amd_fastacosf")
+TLI_DEFINE_FAST_AOCL_FUNC("__acosf_finite", "amd_fastacosf")
+TLI_DEFINE_FAST_AOCL_FUNC("acos", "amd_fastacos")
+TLI_DEFINE_FAST_AOCL_FUNC("__acos_finite", "amd_fastacos")
+
+TLI_DEFINE_FAST_AOCL_FUNC("asinf", "amd_fastasinf")
+TLI_DEFINE_FAST_AOCL_FUNC("__asinf_finite", "amd_fastasinf")
+TLI_DEFINE_FAST_AOCL_FUNC("asin", "amd_fastasin")
+TLI_DEFINE_FAST_AOCL_FUNC("__asin_finite", "amd_fastasin")
+
+TLI_DEFINE_FAST_AOCL_FUNC("atanf", "amd_fastatanf")
+TLI_DEFINE_FAST_AOCL_FUNC("__atanf_finite", "amd_fastatanf")
+TLI_DEFINE_FAST_AOCL_FUNC("atan", "amd_fastatan")
+TLI_DEFINE_FAST_AOCL_FUNC("__atan_finite", "amd_fastatan")
+
+TLI_DEFINE_FAST_AOCL_FUNC("cosf", "amd_fastcosf")
+TLI_DEFINE_FAST_AOCL_FUNC("__cosf_finite", "amd_fastcosf")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.cos.f32", "amd_fastcosf")
+TLI_DEFINE_FAST_AOCL_FUNC("cos", "amd_fastcos")
+TLI_DEFINE_FAST_AOCL_FUNC("__cos_finite", "amd_fastcos")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.cos.f64", "amd_fastcos")
+
+TLI_DEFINE_FAST_AOCL_FUNC("erff", "amd_fasterff")
+TLI_DEFINE_FAST_AOCL_FUNC("__erff_finite", "amd_fasterff")
+TLI_DEFINE_FAST_AOCL_FUNC("erf", "amd_fasterf")
+TLI_DEFINE_FAST_AOCL_FUNC("__erf_finite", "amd_fasterf")
+
+TLI_DEFINE_FAST_AOCL_FUNC("expf", "amd_fastexpf")
+TLI_DEFINE_FAST_AOCL_FUNC("__expf_finite", "amd_fastexpf")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.exp.f32", "amd_fastexpf")
+TLI_DEFINE_FAST_AOCL_FUNC("exp", "amd_fastexp")
+TLI_DEFINE_FAST_AOCL_FUNC("__exp_finite", "amd_fastexp")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.exp.f64", "amd_fastexp")
+
+TLI_DEFINE_FAST_AOCL_FUNC("logf", "amd_fastlogf")
+TLI_DEFINE_FAST_AOCL_FUNC("__logf_finite", "amd_fastlogf")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.log.f32", "amd_fastlogf")
+TLI_DEFINE_FAST_AOCL_FUNC("log", "amd_fastlog")
+TLI_DEFINE_FAST_AOCL_FUNC("__log_finite", "amd_fastlog")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.log.f64", "amd_fastlog")
+
+TLI_DEFINE_FAST_AOCL_FUNC("powf", "amd_fastpowf")
+TLI_DEFINE_FAST_AOCL_FUNC("__powf_finite", "amd_fastpowf")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.pow.f32", "amd_fastpowf")
+TLI_DEFINE_FAST_AOCL_FUNC("pow", "amd_fastpow")
+TLI_DEFINE_FAST_AOCL_FUNC("__pow_finite", "amd_fastpow")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.pow.f64", "amd_fastpow")
+
+TLI_DEFINE_FAST_AOCL_FUNC("sinf", "amd_fastsinf")
+TLI_DEFINE_FAST_AOCL_FUNC("__sinf_finite", "amd_fastsinf")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.sin.f32", "amd_fastsinf")
+TLI_DEFINE_FAST_AOCL_FUNC("sin", "amd_fastsin")
+TLI_DEFINE_FAST_AOCL_FUNC("__sin_finite", "amd_fastsin")
+TLI_DEFINE_FAST_AOCL_FUNC("llvm.sin.f64", "amd_fastsin")
+
+TLI_DEFINE_FAST_AOCL_FUNC("tanf", "amd_fasttanf")
+TLI_DEFINE_FAST_AOCL_FUNC("__tanf_finite", "amd_fasttanf")
+TLI_DEFINE_FAST_AOCL_FUNC("tan", "amd_fasttan")
+TLI_DEFINE_FAST_AOCL_FUNC("__tan_finite", "amd_fasttan")
+#endif
+
+#undef TLI_DEFINE_FAST_AOCL_FUNCS
+#undef TLI_DEFINE_FAST_AOCL_FUNC
diff --git a/llvm/include/llvm/Analysis/ScalarAOCLFuncs.def b/llvm/include/llvm/Analysis/ScalarAOCLFuncs.def
deleted file mode 100644
index 906b1612afa5c2..00000000000000
--- a/llvm/include/llvm/Analysis/ScalarAOCLFuncs.def
+++ /dev/null
@@ -1,80 +0,0 @@
-//===-- ScalarAOCLFuncs.def - AMD scalar math library mappings --*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This .def file creates a mapping from standard scalar math functions to
-// their corresponding fast entry points in the AMD AOCL scalar math library.
-// The lowering is only legal under fast-math semantics.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(TLI_DEFINE_SCALAR_AOCL_FUNCS)
-#define TLI_DEFINE_SCALAR_AOCL_FUNC(SCAL, AOCLENTRY) {SCAL, AOCLENTRY},
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("acosf", "amd_fastacosf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__acosf_finite", "amd_fastacosf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("acos", "amd_fastacos")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__acos_finite", "amd_fastacos")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("asinf", "amd_fastasinf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__asinf_finite", "amd_fastasinf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("asin", "amd_fastasin")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__asin_finite", "amd_fastasin")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("atanf", "amd_fastatanf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__atanf_finite", "amd_fastatanf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("atan", "amd_fastatan")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__atan_finite", "amd_fastatan")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("cosf", "amd_fastcosf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__cosf_finite", "amd_fastcosf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.cos.f32", "amd_fastcosf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("cos", "amd_fastcos")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__cos_finite", "amd_fastcos")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.cos.f64", "amd_fastcos")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("erff", "amd_fasterff")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__erff_finite", "amd_fasterff")
-TLI_DEFINE_SCALAR_AOCL_FUNC("erf", "amd_fasterf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__erf_finite", "amd_fasterf")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("expf", "amd_fastexpf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__expf_finite", "amd_fastexpf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.exp.f32", "amd_fastexpf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("exp", "amd_fastexp")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__exp_finite", "amd_fastexp")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.exp.f64", "amd_fastexp")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("logf", "amd_fastlogf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__logf_finite", "amd_fastlogf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.log.f32", "amd_fastlogf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("log", "amd_fastlog")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__log_finite", "amd_fastlog")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.log.f64", "amd_fastlog")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("powf", "amd_fastpowf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__powf_finite", "amd_fastpowf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.pow.f32", "amd_fastpowf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("pow", "amd_fastpow")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__pow_finite", "amd_fastpow")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.pow.f64", "amd_fastpow")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("sinf", "amd_fastsinf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__sinf_finite", "amd_fastsinf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.sin.f32", "amd_fastsinf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("sin", "amd_fastsin")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__sin_finite", "amd_fastsin")
-TLI_DEFINE_SCALAR_AOCL_FUNC("llvm.sin.f64", "amd_fastsin")
-
-TLI_DEFINE_SCALAR_AOCL_FUNC("tanf", "amd_fasttanf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__tanf_finite", "amd_fasttanf")
-TLI_DEFINE_SCALAR_AOCL_FUNC("tan", "amd_fasttan")
-TLI_DEFINE_SCALAR_AOCL_FUNC("__tan_finite", "amd_fasttan")
-#endif
-
-#undef TLI_DEFINE_SCALAR_AOCL_FUNCS
-#undef TLI_DEFINE_SCALAR_AOCL_FUNC
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index 30da53fc0addb8..c6b91d42981d53 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -122,10 +122,10 @@ class TargetLibraryInfoImpl {
/// on VectorFnName rather than ScalarFnName.
std::vector<VecDesc> ScalarDescs;
- /// Mapping from a standard scalar math function name to its AMD scalar math
- /// library fast-call equivalent (e.g. "tan" -> "amd_fasttan"). Populated when
- /// an AMD scalar math library is selected.
- DenseMap<StringRef, StringRef> LibScalarFunctions;
+ /// Mapping from a standard math function name to its AMD fast math library
+ /// fast-call equivalent (e.g. "tan" -> "amd_fasttan"). Populated when an AMD
+ /// fast math library is selected.
+ DenseMap<StringRef, StringRef> LibFastFunctions;
/// Return true if the function type FTy is valid for the library function
/// F, regardless of whether the function is available.
@@ -133,13 +133,13 @@ class TargetLibraryInfoImpl {
const Module &M) const;
public:
- /// Scalar math library selection used for lowering standard scalar math
- /// calls to faster, library-specific entry points.
- enum ScalarLibrary {
- Default_Scalar_Library, // Use default library.
- SCALAR_AMDLIBM // AMD scalar math library.
+ /// Fast math library selection used for lowering standard math calls to
+ /// faster, library-specific entry points.
+ enum FastLibrary {
+ NoFastLibrary, // Use default library.
+ FAST_AMDLIBM // AMD fast math library.
};
- ScalarLibrary ScalarMathLib = Default_Scalar_Library;
+ FastLibrary FastMathLib = NoFastLibrary;
TargetLibraryInfoImpl() = delete;
LLVM_ABI explicit TargetLibraryInfoImpl(
@@ -210,19 +210,19 @@ class TargetLibraryInfoImpl {
addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib,
const llvm::Triple &TargetTriple);
- /// Populate the scalar math function mappings for the given scalar library
- /// and record it as the selected scalar math library.
- LLVM_ABI void addScalarFunctionsFromMathLib(enum ScalarLibrary ScalarLib);
+ /// Populate the fast math function mappings for the given fast math library
+ /// and record it as the selected fast math library.
+ LLVM_ABI void addFastFunctionsFromMathLib(enum FastLibrary FastLib);
- /// Return the library-specific scalar function name for \p F, or an empty
+ /// Return the library-specific fast function name for \p F, or an empty
/// StringRef if no mapping exists.
- LLVM_ABI StringRef getScalarFunctionFromMathLib(StringRef F) const;
+ LLVM_ABI StringRef getFastFunctionFromMathLib(StringRef F) const;
- /// Return the currently selected scalar math library.
- LLVM_ABI ScalarLibrary getScalarMathLib() const;
+ /// Return the currently selected fast math library.
+ LLVM_ABI FastLibrary getFastMathLib() const;
- /// Set the selected scalar math library.
- LLVM_ABI void setScalarMathLib(enum ScalarLibrary ScalarLib);
+ /// Set the selected fast math library.
+ LLVM_ABI void setFastMathLib(enum FastLibrary FastLib);
/// Return true if the function F has a vector equivalent with vectorization
/// factor VF.
@@ -433,11 +433,11 @@ class TargetLibraryInfo {
bool Masked) const {
return Impl->getVectorMappingInfo(F, VF, Masked);
}
- StringRef getScalarFunctionFromMathLib(StringRef F) const {
- return Impl->getScalarFunctionFromMathLib(F);
+ StringRef getFastFunctionFromMathLib(StringRef F) const {
+ return Impl->getFastFunctionFromMathLib(F);
}
- TargetLibraryInfoImpl::ScalarLibrary getScalarMathLib() const {
- return Impl->getScalarMathLib();
+ TargetLibraryInfoImpl::FastLibrary getFastMathLib() const {
+ return Impl->getFastMathLib();
}
/// Tests if the function is both available and a candidate for optimized code
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 7c9313b7089b09..409407d5cad4a9 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -22,13 +22,13 @@
#include "llvm/TargetParser/Triple.h"
using namespace llvm;
-static cl::opt<TargetLibraryInfoImpl::ScalarLibrary> ClScalarLibrary(
+static cl::opt<TargetLibraryInfoImpl::FastLibrary> ClFastLibrary(
"fast-library", cl::Hidden, cl::desc("fast functions library"),
- cl::init(TargetLibraryInfoImpl::Default_Scalar_Library),
- cl::values(clEnumValN(TargetLibraryInfoImpl::Default_Scalar_Library, "none",
+ cl::init(TargetLibraryInfoImpl::NoFastLibrary),
+ cl::values(clEnumValN(TargetLibraryInfoImpl::NoFastLibrary, "none",
"Use default library"),
- clEnumValN(TargetLibraryInfoImpl::SCALAR_AMDLIBM, "AMDLIBM",
- "AMD scalar math library")));
+ clEnumValN(TargetLibraryInfoImpl::FAST_AMDLIBM, "AMDLIBM",
+ "AMD fast math library")));
#define GET_TARGET_LIBRARY_INFO_STRING_TABLE
#include "llvm/Analysis/TargetLibraryInfo.inc"
@@ -922,7 +922,7 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(const Triple &T,
memset(AvailableArray, -1, sizeof(AvailableArray));
initialize(*this, T, StandardNamesStrTable, VecLib);
- addScalarFunctionsFromMathLib(ClScalarLibrary);
+ addFastFunctionsFromMathLib(ClFastLibrary);
}
TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
@@ -934,8 +934,8 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI)
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
VectorDescs = TLI.VectorDescs;
ScalarDescs = TLI.ScalarDescs;
- LibScalarFunctions = TLI.LibScalarFunctions;
- ScalarMathLib = TLI.ScalarMathLib;
+ LibFastFunctions = TLI.LibFastFunctions;
+ FastMathLib = TLI.FastMathLib;
}
TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
@@ -949,8 +949,8 @@ TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI)
AvailableArray);
VectorDescs = TLI.VectorDescs;
ScalarDescs = TLI.ScalarDescs;
- LibScalarFunctions = TLI.LibScalarFunctions;
- ScalarMathLib = TLI.ScalarMathLib;
+ LibFastFunctions = TLI.LibFastFunctions;
+ FastMathLib = TLI.FastMathLib;
}
TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) {
@@ -962,8 +962,8 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoI
SizeOfInt = TLI.SizeOfInt;
IsErrnoFunctionCall = TLI.IsErrnoFunctionCall;
memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
- LibScalarFunctions = TLI.LibScalarFunctions;
- ScalarMathLib = TLI.ScalarMathLib;
+ LibFastFunctions = TLI.LibFastFunctions;
+ FastMathLib = TLI.FastMathLib;
return *this;
}
@@ -977,8 +977,8 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&
IsErrnoFunctionCall = TLI.IsErrnoFunctionCall;
std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
AvailableArray);
- LibScalarFunctions = TLI.LibScalarFunctions;
- ScalarMathLib = TLI.ScalarMathLib;
+ LibFastFunctions = TLI.LibFastFunctions;
+ FastMathLib = TLI.FastMathLib;
return *this;
}
@@ -1431,38 +1431,38 @@ void TargetLibraryInfoImpl::addVectorizableFunctionsFromVecLib(
}
}
-void TargetLibraryInfoImpl::addScalarFunctionsFromMathLib(
- enum ScalarLibrary ScalarLib) {
- setScalarMathLib(ScalarLib);
- switch (ScalarLib) {
- case ScalarLibrary::SCALAR_AMDLIBM: {
- const DenseMap<StringRef, StringRef> ScalarAOCLFuncs = {
-#define TLI_DEFINE_SCALAR_AOCL_FUNCS
-#include "llvm/Analysis/ScalarAOCLFuncs.def"
+void TargetLibraryInfoImpl::addFastFunctionsFromMathLib(
+ enum FastLibrary FastLib) {
+ setFastMathLib(FastLib);
+ switch (FastLib) {
+ case FastLibrary::FAST_AMDLIBM: {
+ const DenseMap<StringRef, StringRef> FastAOCLFuncs = {
+#define TLI_DEFINE_FAST_AOCL_FUNCS
+#include "llvm/Analysis/FastAOCLFuncs.def"
};
- LibScalarFunctions.insert(ScalarAOCLFuncs.begin(), ScalarAOCLFuncs.end());
+ LibFastFunctions.insert(FastAOCLFuncs.begin(), FastAOCLFuncs.end());
break;
}
- case ScalarLibrary::Default_Scalar_Library:
+ case FastLibrary::NoFastLibrary:
break;
}
}
-void TargetLibraryInfoImpl::setScalarMathLib(enum ScalarLibrary ScalarLib) {
- ScalarMathLib = ScalarLib;
+void TargetLibraryInfoImpl::setFastMathLib(enum FastLibrary FastLib) {
+ FastMathLib = FastLib;
}
-StringRef TargetLibraryInfoImpl::getScalarFunctionFromMathLib(
- StringRef ScalarFnName) const {
- auto Iter = LibScalarFunctions.find(ScalarFnName);
- if (Iter == LibScalarFunctions.end())
+StringRef TargetLibraryInfoImpl::getFastFunctionFromMathLib(
+ StringRef FastFnName) const {
+ auto Iter = LibFastFunctions.find(FastFnName);
+ if (Iter == LibFastFunctions.end())
return StringRef();
return Iter->second;
}
-TargetLibraryInfoImpl::ScalarLibrary
-TargetLibraryInfoImpl::getScalarMathLib() const {
- return ScalarMathLib;
+TargetLibraryInfoImpl::FastLibrary
+TargetLibraryInfoImpl::getFastMathLib() const {
+ return FastMathLib;
}
bool TargetLibraryInfoImpl::isFunctionVectorizable(StringRef funcName) const {
diff --git a/llvm/lib/Target/X86/CMakeLists.txt b/llvm/lib/Target/X86/CMakeLists.txt
index cb6c38e8459a9d..16be7917697754 100644
--- a/llvm/lib/Target/X86/CMakeLists.txt
+++ b/llvm/lib/Target/X86/CMakeLists.txt
@@ -56,7 +56,7 @@ set(sources
X86FlagsCopyLowering.cpp
X86FloatingPoint.cpp
X86FrameLowering.cpp
- X86GenScalarAmdFastCalls.cpp
+ X86GenAmdFastCalls.cpp
X86ISelDAGToDAG.cpp
X86ISelLowering.cpp
X86ISelLoweringCall.cpp
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index e790a602e0f082..c3cf8a9c92f3cc 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -483,11 +483,11 @@ class X86ArgumentStackSlotPass
FunctionPass *createX86ArgumentStackSlotLegacyPass();
-/// This pass rewrites scalar math library calls (e.g. tan) to their AMD AOCL
+/// This pass rewrites math library calls (e.g. tan) to their AMD AOCL
/// fast-call equivalents (e.g. amd_fasttan) under fast-math semantics.
-FunctionPass *createX86GenScalarAmdFastCallsPass();
-void initializeX86GenScalarAmdFastCallsPass(PassRegistry &);
-extern char &X86GenScalarAmdFastCallsID;
+FunctionPass *createX86GenAmdFastCallsPass();
+void initializeX86GenAmdFastCallsPass(PassRegistry &);
+extern char &X86GenAmdFastCallsID;
void initializeCompressEVEXLegacyPass(PassRegistry &);
void initializeX86FixupBWInstLegacyPass(PassRegistry &);
diff --git a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp b/llvm/lib/Target/X86/X86GenAmdFastCalls.cpp
similarity index 69%
rename from llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
rename to llvm/lib/Target/X86/X86GenAmdFastCalls.cpp
index 1e89ecccf56a19..7789072cd04fb1 100644
--- a/llvm/lib/Target/X86/X86GenScalarAmdFastCalls.cpp
+++ b/llvm/lib/Target/X86/X86GenAmdFastCalls.cpp
@@ -1,4 +1,4 @@
-//===-- X86GenScalarAmdFastCalls.cpp --------------------------------------===//
+//===-- X86GenAmdFastCalls.cpp --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
//
-// This transformation converts standard scalar math function calls into their
-// corresponding AMD AOCL scalar library entries for X86 targets, e.g.:
+// This transformation converts standard math function calls into their
+// corresponding AMD AOCL fast entry points for X86 targets, e.g.:
// tan ---> amd_fasttan
// Such lowering is only legal under fast-math semantics and when the AMD
// fast math library has been selected (-fast-library=AMDLIBM /
@@ -34,22 +34,22 @@
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
-#define DEBUG_TYPE "x86-gen-scalar-aocl"
+#define DEBUG_TYPE "x86-gen-aocl-fast"
using namespace llvm;
namespace {
-class X86GenScalarAmdFastCalls : public MachineFunctionPass {
+class X86GenAmdFastCalls : public MachineFunctionPass {
public:
static char ID;
- X86GenScalarAmdFastCalls() : MachineFunctionPass(ID) {}
+ X86GenAmdFastCalls() : MachineFunctionPass(ID) {}
bool runOnMachineFunction(MachineFunction &F) override;
StringRef getPassName() const override {
- return "X86 Generate Scalar AOCL Entries";
+ return "X86 Generate AOCL Fast Entries";
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -62,29 +62,29 @@ class X86GenScalarAmdFastCalls : public MachineFunctionPass {
TargetLibraryInfo *TLI = nullptr;
MachineOptimizationRemarkEmitter *ORE = nullptr;
bool isCandidateSafeToLower(MachineInstr *MI) const;
- bool createScalarAOCLCall(MachineInstr *MI) const;
+ bool createAmdFastCall(MachineInstr *MI) const;
};
} // namespace
-// Rewriting a scalar math call to its AOCL fast-call variant is only legal
-// under fast-math semantics. By the time this late machine pass runs, the
+// Rewriting a math call to its AOCL fast-call variant is only legal under
+// fast-math semantics. By the time this late machine pass runs, the
// per-operation fast-math flags carried by the original call have already been
// lowered away, so we rely on the function-level fast-math attribute that the
// frontend sets under -ffast-math. Together with the explicit
// -fast-library=AMDLIBM opt-in (checked in runOnMachineFunction) this gates
// the transformation.
-bool X86GenScalarAmdFastCalls::isCandidateSafeToLower(MachineInstr *MI) const {
+bool X86GenAmdFastCalls::isCandidateSafeToLower(MachineInstr *MI) const {
const Function &F = MI->getMF()->getFunction();
return F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool();
}
-/// Lowers scalar math functions to scalar AOCL functions.
+/// Lowers math functions to AOCL fast entry points.
/// e.g.: tan --> amd_fasttan
/// The callsite symbol is updated during lowering.
-bool X86GenScalarAmdFastCalls::createScalarAOCLCall(MachineInstr *MI) const {
+bool X86GenAmdFastCalls::createAmdFastCall(MachineInstr *MI) const {
StringRef CallSiteName = "";
- StringRef LibScalarFnName = "";
+ StringRef LibFastFnName = "";
if (MI->getOperand(0).isSymbol()) {
CallSiteName = MI->getOperand(0).getSymbolName();
} else if (MI->getOperand(0).isGlobal()) {
@@ -97,29 +97,29 @@ bool X86GenScalarAmdFastCalls::createScalarAOCLCall(MachineInstr *MI) const {
if (CallSiteName.empty()) {
return false;
}
- LibScalarFnName = TLI->getScalarFunctionFromMathLib(CallSiteName);
- if (LibScalarFnName.empty()) {
+ LibFastFnName = TLI->getFastFunctionFromMathLib(CallSiteName);
+ if (LibFastFnName.empty()) {
LLVM_DEBUG(dbgs() << "Fast call not supported\n";);
return false;
}
LLVM_DEBUG(dbgs() << "Candidate Func has fast Call variant available = "
- << LibScalarFnName << "\n";);
- MI->getOperand(0).ChangeToES(LibScalarFnName.data(),
+ << LibFastFnName << "\n";);
+ MI->getOperand(0).ChangeToES(LibFastFnName.data(),
MI->getOperand(0).getTargetFlags());
LLVM_DEBUG(dbgs() << "Successfully replaced with fastcall= "
- << LibScalarFnName << "\n";);
+ << LibFastFnName << "\n";);
ORE->emit([&]() {
return MachineOptimizationRemark(DEBUG_TYPE, "Passed", MI->getDebugLoc(),
MI->getParent())
- << "Successfully replaced with fastcall= " << LibScalarFnName
+ << "Successfully replaced with fastcall= " << LibFastFnName
<< "\n";
});
return true;
}
-bool X86GenScalarAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
+bool X86GenAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
bool Changed = false;
if (skipFunction(MF.getFunction()))
@@ -144,8 +144,8 @@ bool X86GenScalarAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
if (!TLI)
return Changed;
- if (TLI->getScalarMathLib() !=
- TargetLibraryInfoImpl::ScalarLibrary::SCALAR_AMDLIBM) {
+ if (TLI->getFastMathLib() !=
+ TargetLibraryInfoImpl::FastLibrary::FAST_AMDLIBM) {
LLVM_DEBUG(dbgs() << "-fast-library=AMDLIBM not used so bailing out.\n";);
return Changed;
}
@@ -153,24 +153,24 @@ bool X86GenScalarAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
for (auto *CI : Callsites) {
if (isCandidateSafeToLower(CI)) {
LLVM_DEBUG(dbgs() << "Call Inst has fastMath flags\n";);
- Changed |= createScalarAOCLCall(CI);
+ Changed |= createAmdFastCall(CI);
} else
LLVM_DEBUG(dbgs() << "Call Inst does not have fastMath flags\n";);
}
return Changed;
}
-char X86GenScalarAmdFastCalls::ID = 0;
+char X86GenAmdFastCalls::ID = 0;
-char &llvm::X86GenScalarAmdFastCallsID = X86GenScalarAmdFastCalls::ID;
+char &llvm::X86GenAmdFastCallsID = X86GenAmdFastCalls::ID;
-INITIALIZE_PASS_BEGIN(X86GenScalarAmdFastCalls, DEBUG_TYPE,
- "Generate Scalar AMD Fast calls", false, false)
+INITIALIZE_PASS_BEGIN(X86GenAmdFastCalls, DEBUG_TYPE,
+ "Generate AMD Fast calls", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
-INITIALIZE_PASS_END(X86GenScalarAmdFastCalls, DEBUG_TYPE,
- "Generate Scalar AMD Fast calls", false, false)
+INITIALIZE_PASS_END(X86GenAmdFastCalls, DEBUG_TYPE,
+ "Generate AMD Fast calls", false, false)
-FunctionPass *llvm::createX86GenScalarAmdFastCallsPass() {
- return new X86GenScalarAmdFastCalls();
+FunctionPass *llvm::createX86GenAmdFastCallsPass() {
+ return new X86GenAmdFastCalls();
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 7063fce03dcf30..22bf8e09d8abab 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -110,7 +110,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
initializeX86PreLegalizerCombinerLegacyPass(PR);
initializeX86PostLegalizerCombinerLegacyPass(PR);
initializeX86WinEHUnwindV3Pass(PR);
- initializeX86GenScalarAmdFastCallsPass(PR);
+ initializeX86GenAmdFastCallsPass(PR);
}
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
@@ -536,10 +536,10 @@ void X86PassConfig::addPreRegAlloc() {
void X86PassConfig::addMachineSSAOptimization() {
addPass(createX86DomainReassignmentLegacyPass());
- // Generate x86 target-specific function calls for scalar math functions
- // that are available in the AMD AOCL library.
+ // Generate x86 target-specific function calls for math functions that are
+ // available in the AMD AOCL fast math library.
if (getOptLevel() == CodeGenOptLevel::Aggressive)
- addPass(createX86GenScalarAmdFastCallsPass());
+ addPass(createX86GenAmdFastCallsPass());
TargetPassConfig::addMachineSSAOptimization();
}
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll b/llvm/test/CodeGen/X86/aocl-fast-calls-i686.ll
similarity index 100%
rename from llvm/test/CodeGen/X86/aocl-fast-scalar-calls-i686.ll
rename to llvm/test/CodeGen/X86/aocl-fast-calls-i686.ll
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll b/llvm/test/CodeGen/X86/aocl-fast-calls-mappings.ll
similarity index 95%
rename from llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
rename to llvm/test/CodeGen/X86/aocl-fast-calls-mappings.ll
index 64ddcedd0ce61d..ac721d633db0c0 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls-mappings.ll
+++ b/llvm/test/CodeGen/X86/aocl-fast-calls-mappings.ll
@@ -1,5 +1,5 @@
-; Exercises the scalar->AOCL fast-call name mapping under fast-math at -O3 with
-; -fast-library=AMDLIBM on X86: float variants, *_finite aliases and
+; Exercises the fast math->AOCL fast-call name mapping under fast-math at -O3
+; with -fast-library=AMDLIBM on X86: float variants, *_finite aliases and
; inverse-trig functions are rewritten, while math calls with no AOCL mapping
; (e.g. cbrt) are left untouched.
diff --git a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll b/llvm/test/CodeGen/X86/aocl-fast-calls.ll
similarity index 89%
rename from llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
rename to llvm/test/CodeGen/X86/aocl-fast-calls.ll
index 63947c1dd44583..d5dd8dba0bdf33 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-scalar-calls.ll
+++ b/llvm/test/CodeGen/X86/aocl-fast-calls.ll
@@ -1,6 +1,6 @@
-; Verify that, under fast-math at -O3 with -fast-library=AMDLIBM, scalar math
-; library calls are rewritten to their AMD AOCL fast-call equivalents on X86,
-; and that they are left untouched without the option.
+; Verify that, under fast-math at -O3 with -fast-library=AMDLIBM, math library
+; calls are rewritten to their AMD AOCL fast-call equivalents on X86, and that
+; they are left untouched without the option.
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
@@ -48,7 +48,7 @@ entry:
; STD: callq{{.*}}log
; Without the fast-math attributes the call must not be rewritten even when the
-; AMD scalar library is selected.
+; AMD fast math library is selected.
define double @call_tan_no_fastmath(double %x) {
entry:
%r = call double @tan(double %x)
diff --git a/llvm/test/CodeGen/X86/opt-pipeline.ll b/llvm/test/CodeGen/X86/opt-pipeline.ll
index d33f07f903e3a1..2317464151557e 100644
--- a/llvm/test/CodeGen/X86/opt-pipeline.ll
+++ b/llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -96,7 +96,7 @@
; CHECK-NEXT: X86 Domain Reassignment Pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; O3-NEXT: Machine Optimization Remark Emitter
-; O3-NEXT: X86 Generate Scalar AOCL Entries
+; O3-NEXT: X86 Generate AOCL Fast Entries
; O3-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Early Tail Duplication
; CHECK-NEXT: Optimize machine instruction PHIs
>From 5886c6f5963687be9861594e7be2a0dec3f00a42 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Fri, 21 Aug 2026 02:06:53 +0530
Subject: [PATCH 07/10] [X86] Make fast library call lowering pass
vendor-neutral
Make the X86 fast-call lowering pass vendor-neutral by renaming it to X86GenFastCalls, gating on any selected fast library rather than AMDLIBM specifically, and moving AMDLIBM function mappings into AMDLIBMFastFuncs.def. All 5 lit tests pass.
---
clang/include/clang/Basic/CodeGenOptions.h | 2 +-
clang/include/clang/Options/Options.td | 2 +-
clang/lib/CodeGen/BackendUtil.cpp | 4 +-
.../X86/{aocl-fast-calls.c => fast-calls.c} | 4 +-
.../llvm/Analysis/AMDLIBMFastFuncs.def | 78 ++++++++++++++++++
llvm/include/llvm/Analysis/FastAOCLFuncs.def | 80 -------------------
.../include/llvm/Analysis/TargetLibraryInfo.h | 2 +-
llvm/lib/Analysis/TargetLibraryInfo.cpp | 12 +--
llvm/lib/Target/X86/CMakeLists.txt | 2 +-
llvm/lib/Target/X86/X86.h | 10 +--
...enAmdFastCalls.cpp => X86GenFastCalls.cpp} | 58 ++++++--------
llvm/lib/Target/X86/X86TargetMachine.cpp | 7 +-
...-fast-calls-i686.ll => fast-calls-i686.ll} | 2 +-
...lls-mappings.ll => fast-calls-mappings.ll} | 10 +--
.../X86/{aocl-fast-calls.ll => fast-calls.ll} | 8 +-
llvm/test/CodeGen/X86/opt-pipeline.ll | 2 +-
16 files changed, 137 insertions(+), 146 deletions(-)
rename clang/test/CodeGen/X86/{aocl-fast-calls.c => fast-calls.c} (87%)
create mode 100644 llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def
delete mode 100644 llvm/include/llvm/Analysis/FastAOCLFuncs.def
rename llvm/lib/Target/X86/{X86GenAmdFastCalls.cpp => X86GenFastCalls.cpp} (71%)
rename llvm/test/CodeGen/X86/{aocl-fast-calls-i686.ll => fast-calls-i686.ll} (91%)
rename llvm/test/CodeGen/X86/{aocl-fast-calls-mappings.ll => fast-calls-mappings.ll} (92%)
rename llvm/test/CodeGen/X86/{aocl-fast-calls.ll => fast-calls.ll} (89%)
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 91062c654777fc..099ecd05bdbfa5 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -113,7 +113,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
/// Fast math functions library to use with -ffastlib=.
enum FastLibrary {
NoFastLibrary, // Use default library.
- FAST_AMDLIBM // AMD fast math library.
+ AMDLIBM // AMD fast math library.
};
enum ObjCDispatchMethodKind {
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index c2a461c753fc59..af96ce0fef1ee8 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -4030,7 +4030,7 @@ def ffastlib : Joined<["-"], "ffastlib=">, Group<f_Group>,
HelpText<"Use the given fast math functions library.">,
Values<"AMDLIBM,none">,
NormalizedValuesScope<"CodeGenOptions">,
- NormalizedValues<["FAST_AMDLIBM", "NoFastLibrary"]>,
+ NormalizedValues<["AMDLIBM", "NoFastLibrary"]>,
MarshallingInfoEnum<CodeGenOpts<"FastLib">, "NoFastLibrary">;
def fno_lax_vector_conversions : Flag<["-"], "fno-lax-vector-conversions">, Group<f_Group>,
Alias<flax_vector_conversions_EQ>, AliasArgs<["none"]>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 70e6386c18fb46..6151a84f982369 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -151,8 +151,8 @@ static std::string getProfileGenName(const CodeGenOptions &CodeGenOpts) {
static void addFastMathLibrary(TargetLibraryInfoImpl &TLII,
const CodeGenOptions &CodeGenOpts) {
switch (CodeGenOpts.getFastLib()) {
- case CodeGenOptions::FAST_AMDLIBM:
- TLII.addFastFunctionsFromMathLib(TargetLibraryInfoImpl::FAST_AMDLIBM);
+ case CodeGenOptions::AMDLIBM:
+ TLII.addFastFunctionsFromMathLib(TargetLibraryInfoImpl::AMDLIBM);
break;
case CodeGenOptions::NoFastLibrary:
break;
diff --git a/clang/test/CodeGen/X86/aocl-fast-calls.c b/clang/test/CodeGen/X86/fast-calls.c
similarity index 87%
rename from clang/test/CodeGen/X86/aocl-fast-calls.c
rename to clang/test/CodeGen/X86/fast-calls.c
index afd53369d64e97..6f1fe9adde778a 100644
--- a/clang/test/CodeGen/X86/aocl-fast-calls.c
+++ b/clang/test/CodeGen/X86/fast-calls.c
@@ -1,5 +1,5 @@
// Verify that the -ffastlib=AMDLIBM driver flag, together with fast-math at -O3,
-// rewrites math library calls into their AMD AOCL fast-call equivalents for X86,
+// rewrites math library calls into their fast library entry points for X86,
// and leaves them untouched without the flag.
// REQUIRES: x86-registered-target
@@ -33,7 +33,7 @@ float call_tanf(float x) { return tanf(x) + x; }
// STD-LABEL: call_tanf:
// STD: callq{{.*}}tanf
-// cbrt has no AOCL mapping and must stay even with the option enabled.
+// cbrt has no fast library mapping and must stay even with the option enabled.
double call_cbrt(double x) { return cbrt(x) + x; }
// AMD-LABEL: call_cbrt:
// AMD-NOT: amd_fast
diff --git a/llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def b/llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def
new file mode 100644
index 00000000000000..d4966dd81ca9a7
--- /dev/null
+++ b/llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def
@@ -0,0 +1,78 @@
+//===-- AMDLIBMFastFuncs.def - AMDLIBM fast function mappings ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Function mappings for -ffastlib=AMDLIBM / -fast-library=AMDLIBM.
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(TLI_DEFINE_FAST_LIB_FUNCS)
+#define TLI_DEFINE_FAST_LIB_FUNC(STANDARD, FAST) {STANDARD, FAST},
+
+TLI_DEFINE_FAST_LIB_FUNC("acosf", "amd_fastacosf")
+TLI_DEFINE_FAST_LIB_FUNC("__acosf_finite", "amd_fastacosf")
+TLI_DEFINE_FAST_LIB_FUNC("acos", "amd_fastacos")
+TLI_DEFINE_FAST_LIB_FUNC("__acos_finite", "amd_fastacos")
+
+TLI_DEFINE_FAST_LIB_FUNC("asinf", "amd_fastasinf")
+TLI_DEFINE_FAST_LIB_FUNC("__asinf_finite", "amd_fastasinf")
+TLI_DEFINE_FAST_LIB_FUNC("asin", "amd_fastasin")
+TLI_DEFINE_FAST_LIB_FUNC("__asin_finite", "amd_fastasin")
+
+TLI_DEFINE_FAST_LIB_FUNC("atanf", "amd_fastatanf")
+TLI_DEFINE_FAST_LIB_FUNC("__atanf_finite", "amd_fastatanf")
+TLI_DEFINE_FAST_LIB_FUNC("atan", "amd_fastatan")
+TLI_DEFINE_FAST_LIB_FUNC("__atan_finite", "amd_fastatan")
+
+TLI_DEFINE_FAST_LIB_FUNC("cosf", "amd_fastcosf")
+TLI_DEFINE_FAST_LIB_FUNC("__cosf_finite", "amd_fastcosf")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.cos.f32", "amd_fastcosf")
+TLI_DEFINE_FAST_LIB_FUNC("cos", "amd_fastcos")
+TLI_DEFINE_FAST_LIB_FUNC("__cos_finite", "amd_fastcos")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.cos.f64", "amd_fastcos")
+
+TLI_DEFINE_FAST_LIB_FUNC("erff", "amd_fasterff")
+TLI_DEFINE_FAST_LIB_FUNC("__erff_finite", "amd_fasterff")
+TLI_DEFINE_FAST_LIB_FUNC("erf", "amd_fasterf")
+TLI_DEFINE_FAST_LIB_FUNC("__erf_finite", "amd_fasterf")
+
+TLI_DEFINE_FAST_LIB_FUNC("expf", "amd_fastexpf")
+TLI_DEFINE_FAST_LIB_FUNC("__expf_finite", "amd_fastexpf")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.exp.f32", "amd_fastexpf")
+TLI_DEFINE_FAST_LIB_FUNC("exp", "amd_fastexp")
+TLI_DEFINE_FAST_LIB_FUNC("__exp_finite", "amd_fastexp")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.exp.f64", "amd_fastexp")
+
+TLI_DEFINE_FAST_LIB_FUNC("logf", "amd_fastlogf")
+TLI_DEFINE_FAST_LIB_FUNC("__logf_finite", "amd_fastlogf")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.log.f32", "amd_fastlogf")
+TLI_DEFINE_FAST_LIB_FUNC("log", "amd_fastlog")
+TLI_DEFINE_FAST_LIB_FUNC("__log_finite", "amd_fastlog")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.log.f64", "amd_fastlog")
+
+TLI_DEFINE_FAST_LIB_FUNC("powf", "amd_fastpowf")
+TLI_DEFINE_FAST_LIB_FUNC("__powf_finite", "amd_fastpowf")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.pow.f32", "amd_fastpowf")
+TLI_DEFINE_FAST_LIB_FUNC("pow", "amd_fastpow")
+TLI_DEFINE_FAST_LIB_FUNC("__pow_finite", "amd_fastpow")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.pow.f64", "amd_fastpow")
+
+TLI_DEFINE_FAST_LIB_FUNC("sinf", "amd_fastsinf")
+TLI_DEFINE_FAST_LIB_FUNC("__sinf_finite", "amd_fastsinf")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.sin.f32", "amd_fastsinf")
+TLI_DEFINE_FAST_LIB_FUNC("sin", "amd_fastsin")
+TLI_DEFINE_FAST_LIB_FUNC("__sin_finite", "amd_fastsin")
+TLI_DEFINE_FAST_LIB_FUNC("llvm.sin.f64", "amd_fastsin")
+
+TLI_DEFINE_FAST_LIB_FUNC("tanf", "amd_fasttanf")
+TLI_DEFINE_FAST_LIB_FUNC("__tanf_finite", "amd_fasttanf")
+TLI_DEFINE_FAST_LIB_FUNC("tan", "amd_fasttan")
+TLI_DEFINE_FAST_LIB_FUNC("__tan_finite", "amd_fasttan")
+#endif
+
+#undef TLI_DEFINE_FAST_LIB_FUNCS
+#undef TLI_DEFINE_FAST_LIB_FUNC
diff --git a/llvm/include/llvm/Analysis/FastAOCLFuncs.def b/llvm/include/llvm/Analysis/FastAOCLFuncs.def
deleted file mode 100644
index 358ca17f301ae8..00000000000000
--- a/llvm/include/llvm/Analysis/FastAOCLFuncs.def
+++ /dev/null
@@ -1,80 +0,0 @@
-//===-- FastAOCLFuncs.def - AMD fast math library mappings ----*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This .def file creates a mapping from standard math functions to their
-// corresponding fast entry points in the AMD AOCL fast math library. The
-// lowering is only legal under fast-math semantics.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(TLI_DEFINE_FAST_AOCL_FUNCS)
-#define TLI_DEFINE_FAST_AOCL_FUNC(SCAL, AOCLENTRY) {SCAL, AOCLENTRY},
-
-TLI_DEFINE_FAST_AOCL_FUNC("acosf", "amd_fastacosf")
-TLI_DEFINE_FAST_AOCL_FUNC("__acosf_finite", "amd_fastacosf")
-TLI_DEFINE_FAST_AOCL_FUNC("acos", "amd_fastacos")
-TLI_DEFINE_FAST_AOCL_FUNC("__acos_finite", "amd_fastacos")
-
-TLI_DEFINE_FAST_AOCL_FUNC("asinf", "amd_fastasinf")
-TLI_DEFINE_FAST_AOCL_FUNC("__asinf_finite", "amd_fastasinf")
-TLI_DEFINE_FAST_AOCL_FUNC("asin", "amd_fastasin")
-TLI_DEFINE_FAST_AOCL_FUNC("__asin_finite", "amd_fastasin")
-
-TLI_DEFINE_FAST_AOCL_FUNC("atanf", "amd_fastatanf")
-TLI_DEFINE_FAST_AOCL_FUNC("__atanf_finite", "amd_fastatanf")
-TLI_DEFINE_FAST_AOCL_FUNC("atan", "amd_fastatan")
-TLI_DEFINE_FAST_AOCL_FUNC("__atan_finite", "amd_fastatan")
-
-TLI_DEFINE_FAST_AOCL_FUNC("cosf", "amd_fastcosf")
-TLI_DEFINE_FAST_AOCL_FUNC("__cosf_finite", "amd_fastcosf")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.cos.f32", "amd_fastcosf")
-TLI_DEFINE_FAST_AOCL_FUNC("cos", "amd_fastcos")
-TLI_DEFINE_FAST_AOCL_FUNC("__cos_finite", "amd_fastcos")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.cos.f64", "amd_fastcos")
-
-TLI_DEFINE_FAST_AOCL_FUNC("erff", "amd_fasterff")
-TLI_DEFINE_FAST_AOCL_FUNC("__erff_finite", "amd_fasterff")
-TLI_DEFINE_FAST_AOCL_FUNC("erf", "amd_fasterf")
-TLI_DEFINE_FAST_AOCL_FUNC("__erf_finite", "amd_fasterf")
-
-TLI_DEFINE_FAST_AOCL_FUNC("expf", "amd_fastexpf")
-TLI_DEFINE_FAST_AOCL_FUNC("__expf_finite", "amd_fastexpf")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.exp.f32", "amd_fastexpf")
-TLI_DEFINE_FAST_AOCL_FUNC("exp", "amd_fastexp")
-TLI_DEFINE_FAST_AOCL_FUNC("__exp_finite", "amd_fastexp")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.exp.f64", "amd_fastexp")
-
-TLI_DEFINE_FAST_AOCL_FUNC("logf", "amd_fastlogf")
-TLI_DEFINE_FAST_AOCL_FUNC("__logf_finite", "amd_fastlogf")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.log.f32", "amd_fastlogf")
-TLI_DEFINE_FAST_AOCL_FUNC("log", "amd_fastlog")
-TLI_DEFINE_FAST_AOCL_FUNC("__log_finite", "amd_fastlog")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.log.f64", "amd_fastlog")
-
-TLI_DEFINE_FAST_AOCL_FUNC("powf", "amd_fastpowf")
-TLI_DEFINE_FAST_AOCL_FUNC("__powf_finite", "amd_fastpowf")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.pow.f32", "amd_fastpowf")
-TLI_DEFINE_FAST_AOCL_FUNC("pow", "amd_fastpow")
-TLI_DEFINE_FAST_AOCL_FUNC("__pow_finite", "amd_fastpow")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.pow.f64", "amd_fastpow")
-
-TLI_DEFINE_FAST_AOCL_FUNC("sinf", "amd_fastsinf")
-TLI_DEFINE_FAST_AOCL_FUNC("__sinf_finite", "amd_fastsinf")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.sin.f32", "amd_fastsinf")
-TLI_DEFINE_FAST_AOCL_FUNC("sin", "amd_fastsin")
-TLI_DEFINE_FAST_AOCL_FUNC("__sin_finite", "amd_fastsin")
-TLI_DEFINE_FAST_AOCL_FUNC("llvm.sin.f64", "amd_fastsin")
-
-TLI_DEFINE_FAST_AOCL_FUNC("tanf", "amd_fasttanf")
-TLI_DEFINE_FAST_AOCL_FUNC("__tanf_finite", "amd_fasttanf")
-TLI_DEFINE_FAST_AOCL_FUNC("tan", "amd_fasttan")
-TLI_DEFINE_FAST_AOCL_FUNC("__tan_finite", "amd_fasttan")
-#endif
-
-#undef TLI_DEFINE_FAST_AOCL_FUNCS
-#undef TLI_DEFINE_FAST_AOCL_FUNC
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index c6b91d42981d53..bd19ca3e096ab3 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -137,7 +137,7 @@ class TargetLibraryInfoImpl {
/// faster, library-specific entry points.
enum FastLibrary {
NoFastLibrary, // Use default library.
- FAST_AMDLIBM // AMD fast math library.
+ AMDLIBM // AMD fast math library.
};
FastLibrary FastMathLib = NoFastLibrary;
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 409407d5cad4a9..c1e926a10ffd58 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -27,7 +27,7 @@ static cl::opt<TargetLibraryInfoImpl::FastLibrary> ClFastLibrary(
cl::init(TargetLibraryInfoImpl::NoFastLibrary),
cl::values(clEnumValN(TargetLibraryInfoImpl::NoFastLibrary, "none",
"Use default library"),
- clEnumValN(TargetLibraryInfoImpl::FAST_AMDLIBM, "AMDLIBM",
+ clEnumValN(TargetLibraryInfoImpl::AMDLIBM, "AMDLIBM",
"AMD fast math library")));
#define GET_TARGET_LIBRARY_INFO_STRING_TABLE
@@ -1435,12 +1435,12 @@ void TargetLibraryInfoImpl::addFastFunctionsFromMathLib(
enum FastLibrary FastLib) {
setFastMathLib(FastLib);
switch (FastLib) {
- case FastLibrary::FAST_AMDLIBM: {
- const DenseMap<StringRef, StringRef> FastAOCLFuncs = {
-#define TLI_DEFINE_FAST_AOCL_FUNCS
-#include "llvm/Analysis/FastAOCLFuncs.def"
+ case FastLibrary::AMDLIBM: {
+ const DenseMap<StringRef, StringRef> FastLibFuncs = {
+#define TLI_DEFINE_FAST_LIB_FUNCS
+#include "llvm/Analysis/AMDLIBMFastFuncs.def"
};
- LibFastFunctions.insert(FastAOCLFuncs.begin(), FastAOCLFuncs.end());
+ LibFastFunctions.insert(FastLibFuncs.begin(), FastLibFuncs.end());
break;
}
case FastLibrary::NoFastLibrary:
diff --git a/llvm/lib/Target/X86/CMakeLists.txt b/llvm/lib/Target/X86/CMakeLists.txt
index 16be7917697754..8f278a22d18785 100644
--- a/llvm/lib/Target/X86/CMakeLists.txt
+++ b/llvm/lib/Target/X86/CMakeLists.txt
@@ -56,7 +56,7 @@ set(sources
X86FlagsCopyLowering.cpp
X86FloatingPoint.cpp
X86FrameLowering.cpp
- X86GenAmdFastCalls.cpp
+ X86GenFastCalls.cpp
X86ISelDAGToDAG.cpp
X86ISelLowering.cpp
X86ISelLoweringCall.cpp
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index c3cf8a9c92f3cc..bfe7b6ad086c1b 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -483,11 +483,11 @@ class X86ArgumentStackSlotPass
FunctionPass *createX86ArgumentStackSlotLegacyPass();
-/// This pass rewrites math library calls (e.g. tan) to their AMD AOCL
-/// fast-call equivalents (e.g. amd_fasttan) under fast-math semantics.
-FunctionPass *createX86GenAmdFastCallsPass();
-void initializeX86GenAmdFastCallsPass(PassRegistry &);
-extern char &X86GenAmdFastCallsID;
+/// This pass rewrites math library calls to their fast library entry points
+/// under fast-math semantics when a fast math library is selected.
+FunctionPass *createX86GenFastCallsPass();
+void initializeX86GenFastCallsPass(PassRegistry &);
+extern char &X86GenFastCallsID;
void initializeCompressEVEXLegacyPass(PassRegistry &);
void initializeX86FixupBWInstLegacyPass(PassRegistry &);
diff --git a/llvm/lib/Target/X86/X86GenAmdFastCalls.cpp b/llvm/lib/Target/X86/X86GenFastCalls.cpp
similarity index 71%
rename from llvm/lib/Target/X86/X86GenAmdFastCalls.cpp
rename to llvm/lib/Target/X86/X86GenFastCalls.cpp
index 7789072cd04fb1..87fa6298b83334 100644
--- a/llvm/lib/Target/X86/X86GenAmdFastCalls.cpp
+++ b/llvm/lib/Target/X86/X86GenFastCalls.cpp
@@ -1,4 +1,4 @@
-//===-- X86GenAmdFastCalls.cpp --------------------------------------------===//
+//===-- X86GenFastCalls.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,11 +7,8 @@
//===----------------------------------------------------------------------===//
//
// This transformation converts standard math function calls into their
-// corresponding AMD AOCL fast entry points for X86 targets, e.g.:
-// tan ---> amd_fasttan
-// Such lowering is only legal under fast-math semantics and when the AMD
-// fast math library has been selected (-fast-library=AMDLIBM /
-// -ffastlib=AMDLIBM).
+// corresponding fast math library entry points for X86 targets when a fast
+// math library has been selected via -fast-library= / -ffastlib=.
//
//===----------------------------------------------------------------------===//
@@ -34,22 +31,22 @@
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
-#define DEBUG_TYPE "x86-gen-aocl-fast"
+#define DEBUG_TYPE "x86-gen-fast-calls"
using namespace llvm;
namespace {
-class X86GenAmdFastCalls : public MachineFunctionPass {
+class X86GenFastCalls : public MachineFunctionPass {
public:
static char ID;
- X86GenAmdFastCalls() : MachineFunctionPass(ID) {}
+ X86GenFastCalls() : MachineFunctionPass(ID) {}
bool runOnMachineFunction(MachineFunction &F) override;
StringRef getPassName() const override {
- return "X86 Generate AOCL Fast Entries";
+ return "X86 Generate Fast Library Calls";
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -62,27 +59,25 @@ class X86GenAmdFastCalls : public MachineFunctionPass {
TargetLibraryInfo *TLI = nullptr;
MachineOptimizationRemarkEmitter *ORE = nullptr;
bool isCandidateSafeToLower(MachineInstr *MI) const;
- bool createAmdFastCall(MachineInstr *MI) const;
+ bool createFastCall(MachineInstr *MI) const;
};
} // namespace
-// Rewriting a math call to its AOCL fast-call variant is only legal under
+// Rewriting a math call to a fast library entry point is only legal under
// fast-math semantics. By the time this late machine pass runs, the
// per-operation fast-math flags carried by the original call have already been
// lowered away, so we rely on the function-level fast-math attribute that the
-// frontend sets under -ffast-math. Together with the explicit
-// -fast-library=AMDLIBM opt-in (checked in runOnMachineFunction) this gates
-// the transformation.
-bool X86GenAmdFastCalls::isCandidateSafeToLower(MachineInstr *MI) const {
+// frontend sets under -ffast-math. Together with an explicit fast math library
+// selection (checked in runOnMachineFunction) this gates the transformation.
+bool X86GenFastCalls::isCandidateSafeToLower(MachineInstr *MI) const {
const Function &F = MI->getMF()->getFunction();
return F.getFnAttribute("no-signed-zeros-fp-math").getValueAsBool();
}
-/// Lowers math functions to AOCL fast entry points.
-/// e.g.: tan --> amd_fasttan
+/// Lowers math functions to their fast library entry points.
/// The callsite symbol is updated during lowering.
-bool X86GenAmdFastCalls::createAmdFastCall(MachineInstr *MI) const {
+bool X86GenFastCalls::createFastCall(MachineInstr *MI) const {
StringRef CallSiteName = "";
StringRef LibFastFnName = "";
if (MI->getOperand(0).isSymbol()) {
@@ -119,7 +114,7 @@ bool X86GenAmdFastCalls::createAmdFastCall(MachineInstr *MI) const {
return true;
}
-bool X86GenAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
+bool X86GenFastCalls::runOnMachineFunction(MachineFunction &MF) {
bool Changed = false;
if (skipFunction(MF.getFunction()))
@@ -144,33 +139,32 @@ bool X86GenAmdFastCalls::runOnMachineFunction(MachineFunction &MF) {
if (!TLI)
return Changed;
- if (TLI->getFastMathLib() !=
- TargetLibraryInfoImpl::FastLibrary::FAST_AMDLIBM) {
- LLVM_DEBUG(dbgs() << "-fast-library=AMDLIBM not used so bailing out.\n";);
+ if (TLI->getFastMathLib() == TargetLibraryInfoImpl::FastLibrary::NoFastLibrary) {
+ LLVM_DEBUG(dbgs() << "No fast math library selected, bailing out.\n";);
return Changed;
}
for (auto *CI : Callsites) {
if (isCandidateSafeToLower(CI)) {
LLVM_DEBUG(dbgs() << "Call Inst has fastMath flags\n";);
- Changed |= createAmdFastCall(CI);
+ Changed |= createFastCall(CI);
} else
LLVM_DEBUG(dbgs() << "Call Inst does not have fastMath flags\n";);
}
return Changed;
}
-char X86GenAmdFastCalls::ID = 0;
+char X86GenFastCalls::ID = 0;
-char &llvm::X86GenAmdFastCallsID = X86GenAmdFastCalls::ID;
+char &llvm::X86GenFastCallsID = X86GenFastCalls::ID;
-INITIALIZE_PASS_BEGIN(X86GenAmdFastCalls, DEBUG_TYPE,
- "Generate AMD Fast calls", false, false)
+INITIALIZE_PASS_BEGIN(X86GenFastCalls, DEBUG_TYPE,
+ "Generate Fast Library Calls", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
-INITIALIZE_PASS_END(X86GenAmdFastCalls, DEBUG_TYPE,
- "Generate AMD Fast calls", false, false)
+INITIALIZE_PASS_END(X86GenFastCalls, DEBUG_TYPE,
+ "Generate Fast Library Calls", false, false)
-FunctionPass *llvm::createX86GenAmdFastCallsPass() {
- return new X86GenAmdFastCalls();
+FunctionPass *llvm::createX86GenFastCallsPass() {
+ return new X86GenFastCalls();
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 22bf8e09d8abab..e3f65e758c98b3 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -110,7 +110,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
initializeX86PreLegalizerCombinerLegacyPass(PR);
initializeX86PostLegalizerCombinerLegacyPass(PR);
initializeX86WinEHUnwindV3Pass(PR);
- initializeX86GenAmdFastCallsPass(PR);
+ initializeX86GenFastCallsPass(PR);
}
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
@@ -536,10 +536,9 @@ void X86PassConfig::addPreRegAlloc() {
void X86PassConfig::addMachineSSAOptimization() {
addPass(createX86DomainReassignmentLegacyPass());
- // Generate x86 target-specific function calls for math functions that are
- // available in the AMD AOCL fast math library.
+ // Generate x86 target-specific fast math library calls.
if (getOptLevel() == CodeGenOptLevel::Aggressive)
- addPass(createX86GenAmdFastCallsPass());
+ addPass(createX86GenFastCallsPass());
TargetPassConfig::addMachineSSAOptimization();
}
diff --git a/llvm/test/CodeGen/X86/aocl-fast-calls-i686.ll b/llvm/test/CodeGen/X86/fast-calls-i686.ll
similarity index 91%
rename from llvm/test/CodeGen/X86/aocl-fast-calls-i686.ll
rename to llvm/test/CodeGen/X86/fast-calls-i686.ll
index 9025ae01096957..7cbf8837be802d 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-calls-i686.ll
+++ b/llvm/test/CodeGen/X86/fast-calls-i686.ll
@@ -1,4 +1,4 @@
-; The AOCL fast-call lowering applies to 32-bit X86 (i686) as well as x86_64.
+; Fast library call lowering applies to 32-bit X86 (i686) as well as x86_64.
; RUN: llc -mtriple=i686-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
diff --git a/llvm/test/CodeGen/X86/aocl-fast-calls-mappings.ll b/llvm/test/CodeGen/X86/fast-calls-mappings.ll
similarity index 92%
rename from llvm/test/CodeGen/X86/aocl-fast-calls-mappings.ll
rename to llvm/test/CodeGen/X86/fast-calls-mappings.ll
index ac721d633db0c0..467581804bc3db 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-calls-mappings.ll
+++ b/llvm/test/CodeGen/X86/fast-calls-mappings.ll
@@ -1,7 +1,7 @@
-; Exercises the fast math->AOCL fast-call name mapping under fast-math at -O3
-; with -fast-library=AMDLIBM on X86: float variants, *_finite aliases and
-; inverse-trig functions are rewritten, while math calls with no AOCL mapping
-; (e.g. cbrt) are left untouched.
+; Exercises the fast math library name mapping under fast-math at -O3 with
+; -fast-library=AMDLIBM on X86: float variants, *_finite aliases and
+; inverse-trig functions are rewritten, while math calls with no fast library
+; mapping (e.g. cbrt) are left untouched.
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
@@ -111,7 +111,7 @@ define double @call_exp_finite(double %x) #0 {
; AMD-LABEL: call_exp_finite:
; AMD: callq{{.*}}amd_fastexp
-; cbrt has no AOCL mapping and must not be rewritten.
+; cbrt has no fast library mapping and must not be rewritten.
define double @call_cbrt_unmapped(double %x) #0 {
%r = call double @cbrt(double %x)
%a = fadd double %r, %x
diff --git a/llvm/test/CodeGen/X86/aocl-fast-calls.ll b/llvm/test/CodeGen/X86/fast-calls.ll
similarity index 89%
rename from llvm/test/CodeGen/X86/aocl-fast-calls.ll
rename to llvm/test/CodeGen/X86/fast-calls.ll
index d5dd8dba0bdf33..7b9af19f8f10ee 100644
--- a/llvm/test/CodeGen/X86/aocl-fast-calls.ll
+++ b/llvm/test/CodeGen/X86/fast-calls.ll
@@ -1,6 +1,6 @@
; Verify that, under fast-math at -O3 with -fast-library=AMDLIBM, math library
-; calls are rewritten to their AMD AOCL fast-call equivalents on X86, and that
-; they are left untouched without the option.
+; calls are rewritten to their fast library entry points on X86, and that they
+; are left untouched without the option.
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -O3 -fast-library=AMDLIBM < %s \
; RUN: | FileCheck %s --check-prefix=AMD
@@ -47,8 +47,8 @@ entry:
; STD-LABEL: call_log:
; STD: callq{{.*}}log
-; Without the fast-math attributes the call must not be rewritten even when the
-; AMD fast math library is selected.
+; Without the fast-math attributes the call must not be rewritten even when a
+; fast math library is selected.
define double @call_tan_no_fastmath(double %x) {
entry:
%r = call double @tan(double %x)
diff --git a/llvm/test/CodeGen/X86/opt-pipeline.ll b/llvm/test/CodeGen/X86/opt-pipeline.ll
index 2317464151557e..f532882b7a81fa 100644
--- a/llvm/test/CodeGen/X86/opt-pipeline.ll
+++ b/llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -96,7 +96,7 @@
; CHECK-NEXT: X86 Domain Reassignment Pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; O3-NEXT: Machine Optimization Remark Emitter
-; O3-NEXT: X86 Generate AOCL Fast Entries
+; O3-NEXT: X86 Generate Fast Library Calls
; O3-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Early Tail Duplication
; CHECK-NEXT: Optimize machine instruction PHIs
>From 75f60455998c3982554bb4fa2f4ec0b6f7cd05f2 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Fri, 21 Aug 2026 02:14:35 +0530
Subject: [PATCH 08/10] [TLI] Rename AMDLIBMFastFuncs.def to shared
FastFuncs.def
Rename AMDLIBMFastFuncs.def to FastFuncs.def following the VecFuncs.def multi-library pattern, with AMDLIBM mappings under TLI_DEFINE_AMDLIBM_FASTFUNCS. All 5 lit tests pass.
---
.../llvm/Analysis/AMDLIBMFastFuncs.def | 78 -----------------
llvm/include/llvm/Analysis/FastFuncs.def | 84 +++++++++++++++++++
llvm/include/module.modulemap | 1 +
llvm/lib/Analysis/TargetLibraryInfo.cpp | 24 +++---
llvm/lib/Target/X86/X86GenFastCalls.cpp | 14 ++--
5 files changed, 105 insertions(+), 96 deletions(-)
delete mode 100644 llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def
create mode 100644 llvm/include/llvm/Analysis/FastFuncs.def
diff --git a/llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def b/llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def
deleted file mode 100644
index d4966dd81ca9a7..00000000000000
--- a/llvm/include/llvm/Analysis/AMDLIBMFastFuncs.def
+++ /dev/null
@@ -1,78 +0,0 @@
-//===-- AMDLIBMFastFuncs.def - AMDLIBM fast function mappings ---*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Function mappings for -ffastlib=AMDLIBM / -fast-library=AMDLIBM.
-//
-//===----------------------------------------------------------------------===//
-
-#if defined(TLI_DEFINE_FAST_LIB_FUNCS)
-#define TLI_DEFINE_FAST_LIB_FUNC(STANDARD, FAST) {STANDARD, FAST},
-
-TLI_DEFINE_FAST_LIB_FUNC("acosf", "amd_fastacosf")
-TLI_DEFINE_FAST_LIB_FUNC("__acosf_finite", "amd_fastacosf")
-TLI_DEFINE_FAST_LIB_FUNC("acos", "amd_fastacos")
-TLI_DEFINE_FAST_LIB_FUNC("__acos_finite", "amd_fastacos")
-
-TLI_DEFINE_FAST_LIB_FUNC("asinf", "amd_fastasinf")
-TLI_DEFINE_FAST_LIB_FUNC("__asinf_finite", "amd_fastasinf")
-TLI_DEFINE_FAST_LIB_FUNC("asin", "amd_fastasin")
-TLI_DEFINE_FAST_LIB_FUNC("__asin_finite", "amd_fastasin")
-
-TLI_DEFINE_FAST_LIB_FUNC("atanf", "amd_fastatanf")
-TLI_DEFINE_FAST_LIB_FUNC("__atanf_finite", "amd_fastatanf")
-TLI_DEFINE_FAST_LIB_FUNC("atan", "amd_fastatan")
-TLI_DEFINE_FAST_LIB_FUNC("__atan_finite", "amd_fastatan")
-
-TLI_DEFINE_FAST_LIB_FUNC("cosf", "amd_fastcosf")
-TLI_DEFINE_FAST_LIB_FUNC("__cosf_finite", "amd_fastcosf")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.cos.f32", "amd_fastcosf")
-TLI_DEFINE_FAST_LIB_FUNC("cos", "amd_fastcos")
-TLI_DEFINE_FAST_LIB_FUNC("__cos_finite", "amd_fastcos")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.cos.f64", "amd_fastcos")
-
-TLI_DEFINE_FAST_LIB_FUNC("erff", "amd_fasterff")
-TLI_DEFINE_FAST_LIB_FUNC("__erff_finite", "amd_fasterff")
-TLI_DEFINE_FAST_LIB_FUNC("erf", "amd_fasterf")
-TLI_DEFINE_FAST_LIB_FUNC("__erf_finite", "amd_fasterf")
-
-TLI_DEFINE_FAST_LIB_FUNC("expf", "amd_fastexpf")
-TLI_DEFINE_FAST_LIB_FUNC("__expf_finite", "amd_fastexpf")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.exp.f32", "amd_fastexpf")
-TLI_DEFINE_FAST_LIB_FUNC("exp", "amd_fastexp")
-TLI_DEFINE_FAST_LIB_FUNC("__exp_finite", "amd_fastexp")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.exp.f64", "amd_fastexp")
-
-TLI_DEFINE_FAST_LIB_FUNC("logf", "amd_fastlogf")
-TLI_DEFINE_FAST_LIB_FUNC("__logf_finite", "amd_fastlogf")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.log.f32", "amd_fastlogf")
-TLI_DEFINE_FAST_LIB_FUNC("log", "amd_fastlog")
-TLI_DEFINE_FAST_LIB_FUNC("__log_finite", "amd_fastlog")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.log.f64", "amd_fastlog")
-
-TLI_DEFINE_FAST_LIB_FUNC("powf", "amd_fastpowf")
-TLI_DEFINE_FAST_LIB_FUNC("__powf_finite", "amd_fastpowf")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.pow.f32", "amd_fastpowf")
-TLI_DEFINE_FAST_LIB_FUNC("pow", "amd_fastpow")
-TLI_DEFINE_FAST_LIB_FUNC("__pow_finite", "amd_fastpow")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.pow.f64", "amd_fastpow")
-
-TLI_DEFINE_FAST_LIB_FUNC("sinf", "amd_fastsinf")
-TLI_DEFINE_FAST_LIB_FUNC("__sinf_finite", "amd_fastsinf")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.sin.f32", "amd_fastsinf")
-TLI_DEFINE_FAST_LIB_FUNC("sin", "amd_fastsin")
-TLI_DEFINE_FAST_LIB_FUNC("__sin_finite", "amd_fastsin")
-TLI_DEFINE_FAST_LIB_FUNC("llvm.sin.f64", "amd_fastsin")
-
-TLI_DEFINE_FAST_LIB_FUNC("tanf", "amd_fasttanf")
-TLI_DEFINE_FAST_LIB_FUNC("__tanf_finite", "amd_fasttanf")
-TLI_DEFINE_FAST_LIB_FUNC("tan", "amd_fasttan")
-TLI_DEFINE_FAST_LIB_FUNC("__tan_finite", "amd_fasttan")
-#endif
-
-#undef TLI_DEFINE_FAST_LIB_FUNCS
-#undef TLI_DEFINE_FAST_LIB_FUNC
diff --git a/llvm/include/llvm/Analysis/FastFuncs.def b/llvm/include/llvm/Analysis/FastFuncs.def
new file mode 100644
index 00000000000000..0ae3a1f96b0233
--- /dev/null
+++ b/llvm/include/llvm/Analysis/FastFuncs.def
@@ -0,0 +1,84 @@
+//===-- FastFuncs.def - Fast math library mappings ----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This .def file creates mappings from standard math functions to their
+// corresponding fast math library entry points. The current support includes
+// such mappings for AMDLIBM. Additional libraries can add their own guarded
+// sections below, similar to VecFuncs.def.
+//
+//===----------------------------------------------------------------------===//
+
+#if !(defined(TLI_DEFINE_FASTFUNC))
+#define TLI_DEFINE_FASTFUNC(STANDARD, FAST) {STANDARD, FAST},
+#endif
+
+#if defined(TLI_DEFINE_AMDLIBM_FASTFUNCS)
+
+TLI_DEFINE_FASTFUNC("acosf", "amd_fastacosf")
+TLI_DEFINE_FASTFUNC("__acosf_finite", "amd_fastacosf")
+TLI_DEFINE_FASTFUNC("acos", "amd_fastacos")
+TLI_DEFINE_FASTFUNC("__acos_finite", "amd_fastacos")
+
+TLI_DEFINE_FASTFUNC("asinf", "amd_fastasinf")
+TLI_DEFINE_FASTFUNC("__asinf_finite", "amd_fastasinf")
+TLI_DEFINE_FASTFUNC("asin", "amd_fastasin")
+TLI_DEFINE_FASTFUNC("__asin_finite", "amd_fastasin")
+
+TLI_DEFINE_FASTFUNC("atanf", "amd_fastatanf")
+TLI_DEFINE_FASTFUNC("__atanf_finite", "amd_fastatanf")
+TLI_DEFINE_FASTFUNC("atan", "amd_fastatan")
+TLI_DEFINE_FASTFUNC("__atan_finite", "amd_fastatan")
+
+TLI_DEFINE_FASTFUNC("cosf", "amd_fastcosf")
+TLI_DEFINE_FASTFUNC("__cosf_finite", "amd_fastcosf")
+TLI_DEFINE_FASTFUNC("llvm.cos.f32", "amd_fastcosf")
+TLI_DEFINE_FASTFUNC("cos", "amd_fastcos")
+TLI_DEFINE_FASTFUNC("__cos_finite", "amd_fastcos")
+TLI_DEFINE_FASTFUNC("llvm.cos.f64", "amd_fastcos")
+
+TLI_DEFINE_FASTFUNC("erff", "amd_fasterff")
+TLI_DEFINE_FASTFUNC("__erff_finite", "amd_fasterff")
+TLI_DEFINE_FASTFUNC("erf", "amd_fasterf")
+TLI_DEFINE_FASTFUNC("__erf_finite", "amd_fasterf")
+
+TLI_DEFINE_FASTFUNC("expf", "amd_fastexpf")
+TLI_DEFINE_FASTFUNC("__expf_finite", "amd_fastexpf")
+TLI_DEFINE_FASTFUNC("llvm.exp.f32", "amd_fastexpf")
+TLI_DEFINE_FASTFUNC("exp", "amd_fastexp")
+TLI_DEFINE_FASTFUNC("__exp_finite", "amd_fastexp")
+TLI_DEFINE_FASTFUNC("llvm.exp.f64", "amd_fastexp")
+
+TLI_DEFINE_FASTFUNC("logf", "amd_fastlogf")
+TLI_DEFINE_FASTFUNC("__logf_finite", "amd_fastlogf")
+TLI_DEFINE_FASTFUNC("llvm.log.f32", "amd_fastlogf")
+TLI_DEFINE_FASTFUNC("log", "amd_fastlog")
+TLI_DEFINE_FASTFUNC("__log_finite", "amd_fastlog")
+TLI_DEFINE_FASTFUNC("llvm.log.f64", "amd_fastlog")
+
+TLI_DEFINE_FASTFUNC("powf", "amd_fastpowf")
+TLI_DEFINE_FASTFUNC("__powf_finite", "amd_fastpowf")
+TLI_DEFINE_FASTFUNC("llvm.pow.f32", "amd_fastpowf")
+TLI_DEFINE_FASTFUNC("pow", "amd_fastpow")
+TLI_DEFINE_FASTFUNC("__pow_finite", "amd_fastpow")
+TLI_DEFINE_FASTFUNC("llvm.pow.f64", "amd_fastpow")
+
+TLI_DEFINE_FASTFUNC("sinf", "amd_fastsinf")
+TLI_DEFINE_FASTFUNC("__sinf_finite", "amd_fastsinf")
+TLI_DEFINE_FASTFUNC("llvm.sin.f32", "amd_fastsinf")
+TLI_DEFINE_FASTFUNC("sin", "amd_fastsin")
+TLI_DEFINE_FASTFUNC("__sin_finite", "amd_fastsin")
+TLI_DEFINE_FASTFUNC("llvm.sin.f64", "amd_fastsin")
+
+TLI_DEFINE_FASTFUNC("tanf", "amd_fasttanf")
+TLI_DEFINE_FASTFUNC("__tanf_finite", "amd_fasttanf")
+TLI_DEFINE_FASTFUNC("tan", "amd_fasttan")
+TLI_DEFINE_FASTFUNC("__tan_finite", "amd_fasttan")
+
+#endif
+
+#undef TLI_DEFINE_FASTFUNC
diff --git a/llvm/include/module.modulemap b/llvm/include/module.modulemap
index 69836bf2e3158d..a0a5595d826640 100644
--- a/llvm/include/module.modulemap
+++ b/llvm/include/module.modulemap
@@ -10,6 +10,7 @@ module LLVM_Analysis {
// This is intended for (repeated) textual inclusion.
textual header "llvm/Analysis/ScalarFuncs.def"
+ textual header "llvm/Analysis/FastFuncs.def"
textual header "llvm/Analysis/VecFuncs.def"
}
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index c1e926a10ffd58..cfa07afcd54d83 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -22,13 +22,14 @@
#include "llvm/TargetParser/Triple.h"
using namespace llvm;
-static cl::opt<TargetLibraryInfoImpl::FastLibrary> ClFastLibrary(
- "fast-library", cl::Hidden, cl::desc("fast functions library"),
- cl::init(TargetLibraryInfoImpl::NoFastLibrary),
- cl::values(clEnumValN(TargetLibraryInfoImpl::NoFastLibrary, "none",
- "Use default library"),
- clEnumValN(TargetLibraryInfoImpl::AMDLIBM, "AMDLIBM",
- "AMD fast math library")));
+static cl::opt<TargetLibraryInfoImpl::FastLibrary>
+ ClFastLibrary("fast-library", cl::Hidden,
+ cl::desc("fast functions library"),
+ cl::init(TargetLibraryInfoImpl::NoFastLibrary),
+ cl::values(clEnumValN(TargetLibraryInfoImpl::NoFastLibrary,
+ "none", "Use default library"),
+ clEnumValN(TargetLibraryInfoImpl::AMDLIBM,
+ "AMDLIBM", "AMD fast math library")));
#define GET_TARGET_LIBRARY_INFO_STRING_TABLE
#include "llvm/Analysis/TargetLibraryInfo.inc"
@@ -1437,8 +1438,9 @@ void TargetLibraryInfoImpl::addFastFunctionsFromMathLib(
switch (FastLib) {
case FastLibrary::AMDLIBM: {
const DenseMap<StringRef, StringRef> FastLibFuncs = {
-#define TLI_DEFINE_FAST_LIB_FUNCS
-#include "llvm/Analysis/AMDLIBMFastFuncs.def"
+#define TLI_DEFINE_AMDLIBM_FASTFUNCS
+#include "llvm/Analysis/FastFuncs.def"
+#undef TLI_DEFINE_AMDLIBM_FASTFUNCS
};
LibFastFunctions.insert(FastLibFuncs.begin(), FastLibFuncs.end());
break;
@@ -1452,8 +1454,8 @@ void TargetLibraryInfoImpl::setFastMathLib(enum FastLibrary FastLib) {
FastMathLib = FastLib;
}
-StringRef TargetLibraryInfoImpl::getFastFunctionFromMathLib(
- StringRef FastFnName) const {
+StringRef
+TargetLibraryInfoImpl::getFastFunctionFromMathLib(StringRef FastFnName) const {
auto Iter = LibFastFunctions.find(FastFnName);
if (Iter == LibFastFunctions.end())
return StringRef();
diff --git a/llvm/lib/Target/X86/X86GenFastCalls.cpp b/llvm/lib/Target/X86/X86GenFastCalls.cpp
index 87fa6298b83334..ea6892e17b0f34 100644
--- a/llvm/lib/Target/X86/X86GenFastCalls.cpp
+++ b/llvm/lib/Target/X86/X86GenFastCalls.cpp
@@ -102,14 +102,13 @@ bool X86GenFastCalls::createFastCall(MachineInstr *MI) const {
MI->getOperand(0).ChangeToES(LibFastFnName.data(),
MI->getOperand(0).getTargetFlags());
- LLVM_DEBUG(dbgs() << "Successfully replaced with fastcall= "
- << LibFastFnName << "\n";);
+ LLVM_DEBUG(dbgs() << "Successfully replaced with fastcall= " << LibFastFnName
+ << "\n";);
ORE->emit([&]() {
return MachineOptimizationRemark(DEBUG_TYPE, "Passed", MI->getDebugLoc(),
MI->getParent())
- << "Successfully replaced with fastcall= " << LibFastFnName
- << "\n";
+ << "Successfully replaced with fastcall= " << LibFastFnName << "\n";
});
return true;
}
@@ -139,7 +138,8 @@ bool X86GenFastCalls::runOnMachineFunction(MachineFunction &MF) {
if (!TLI)
return Changed;
- if (TLI->getFastMathLib() == TargetLibraryInfoImpl::FastLibrary::NoFastLibrary) {
+ if (TLI->getFastMathLib() ==
+ TargetLibraryInfoImpl::FastLibrary::NoFastLibrary) {
LLVM_DEBUG(dbgs() << "No fast math library selected, bailing out.\n";);
return Changed;
}
@@ -162,8 +162,8 @@ INITIALIZE_PASS_BEGIN(X86GenFastCalls, DEBUG_TYPE,
"Generate Fast Library Calls", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
-INITIALIZE_PASS_END(X86GenFastCalls, DEBUG_TYPE,
- "Generate Fast Library Calls", false, false)
+INITIALIZE_PASS_END(X86GenFastCalls, DEBUG_TYPE, "Generate Fast Library Calls",
+ false, false)
FunctionPass *llvm::createX86GenFastCallsPass() {
return new X86GenFastCalls();
>From a5660953321035eee6171ba04a756b86b3224a41 Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Mon, 7 Sep 2026 13:37:14 +0530
Subject: [PATCH 09/10] [TLI] Add AMDLIBM fast mappings for atan2 and expm1
Rewrite atan2/__atan2_finite and expm1 to amd_fastatan2 and amd_fastexpm1 under -ffastlib=AMDLIBM.
---
clang/test/CodeGen/X86/fast-calls.c | 14 ++++++++++
llvm/include/llvm/Analysis/FastFuncs.def | 3 ++
llvm/test/CodeGen/X86/fast-calls-mappings.ll | 29 ++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/clang/test/CodeGen/X86/fast-calls.c b/clang/test/CodeGen/X86/fast-calls.c
index 6f1fe9adde778a..26e843297a3009 100644
--- a/clang/test/CodeGen/X86/fast-calls.c
+++ b/clang/test/CodeGen/X86/fast-calls.c
@@ -11,6 +11,8 @@
double tan(double);
double exp(double);
+double atan2(double, double);
+double expm1(double);
float tanf(float);
double cbrt(double);
@@ -26,6 +28,18 @@ double call_exp(double x) { return exp(x) + x; }
// STD-LABEL: call_exp:
// STD: callq{{.*}}exp
+double call_atan2(double y, double x) { return atan2(y, x) + x; }
+// AMD-LABEL: call_atan2:
+// AMD: callq{{.*}}amd_fastatan2
+// STD-LABEL: call_atan2:
+// STD: callq{{.*}}atan2
+
+double call_expm1(double x) { return expm1(x) + x; }
+// AMD-LABEL: call_expm1:
+// AMD: callq{{.*}}amd_fastexpm1
+// STD-LABEL: call_expm1:
+// STD: callq{{.*}}expm1
+
// Single-precision variant is rewritten too.
float call_tanf(float x) { return tanf(x) + x; }
// AMD-LABEL: call_tanf:
diff --git a/llvm/include/llvm/Analysis/FastFuncs.def b/llvm/include/llvm/Analysis/FastFuncs.def
index 0ae3a1f96b0233..9ae1034be47e28 100644
--- a/llvm/include/llvm/Analysis/FastFuncs.def
+++ b/llvm/include/llvm/Analysis/FastFuncs.def
@@ -33,6 +33,8 @@ TLI_DEFINE_FASTFUNC("atanf", "amd_fastatanf")
TLI_DEFINE_FASTFUNC("__atanf_finite", "amd_fastatanf")
TLI_DEFINE_FASTFUNC("atan", "amd_fastatan")
TLI_DEFINE_FASTFUNC("__atan_finite", "amd_fastatan")
+TLI_DEFINE_FASTFUNC("atan2", "amd_fastatan2")
+TLI_DEFINE_FASTFUNC("__atan2_finite", "amd_fastatan2")
TLI_DEFINE_FASTFUNC("cosf", "amd_fastcosf")
TLI_DEFINE_FASTFUNC("__cosf_finite", "amd_fastcosf")
@@ -52,6 +54,7 @@ TLI_DEFINE_FASTFUNC("llvm.exp.f32", "amd_fastexpf")
TLI_DEFINE_FASTFUNC("exp", "amd_fastexp")
TLI_DEFINE_FASTFUNC("__exp_finite", "amd_fastexp")
TLI_DEFINE_FASTFUNC("llvm.exp.f64", "amd_fastexp")
+TLI_DEFINE_FASTFUNC("expm1", "amd_fastexpm1")
TLI_DEFINE_FASTFUNC("logf", "amd_fastlogf")
TLI_DEFINE_FASTFUNC("__logf_finite", "amd_fastlogf")
diff --git a/llvm/test/CodeGen/X86/fast-calls-mappings.ll b/llvm/test/CodeGen/X86/fast-calls-mappings.ll
index 467581804bc3db..2cd6cb923d2d64 100644
--- a/llvm/test/CodeGen/X86/fast-calls-mappings.ll
+++ b/llvm/test/CodeGen/X86/fast-calls-mappings.ll
@@ -13,7 +13,10 @@ declare float @powf(float, float)
declare double @acos(double)
declare float @acosf(float)
declare double @atan(double)
+declare double @atan2(double, double)
+declare double @__atan2_finite(double, double)
declare double @cos(double)
+declare double @expm1(double)
declare float @sinf(float)
declare double @erf(double)
declare double @__exp_finite(double)
@@ -57,6 +60,23 @@ define double @call_atan(double %x) #0 {
; AMD-LABEL: call_atan:
; AMD: callq{{.*}}amd_fastatan
+; Two-argument inverse-trig: atan2 -> amd_fastatan2
+define double @call_atan2(double %y, double %x) #0 {
+ %r = call double @atan2(double %y, double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_atan2:
+; AMD: callq{{.*}}amd_fastatan2
+
+define double @call_atan2_finite(double %y, double %x) #0 {
+ %r = call double @__atan2_finite(double %y, double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_atan2_finite:
+; AMD: callq{{.*}}amd_fastatan2
+
; Single-precision inverse-trig: acosf -> amd_fastacosf
define float @call_acosf(float %x) #0 {
%r = call float @acosf(float %x)
@@ -111,6 +131,15 @@ define double @call_exp_finite(double %x) #0 {
; AMD-LABEL: call_exp_finite:
; AMD: callq{{.*}}amd_fastexp
+; expm1(double) -> amd_fastexpm1
+define double @call_expm1(double %x) #0 {
+ %r = call double @expm1(double %x)
+ %a = fadd double %r, %x
+ ret double %a
+}
+; AMD-LABEL: call_expm1:
+; AMD: callq{{.*}}amd_fastexpm1
+
; cbrt has no fast library mapping and must not be rewritten.
define double @call_cbrt_unmapped(double %x) #0 {
%r = call double @cbrt(double %x)
>From 63d983389b64b57e7dbffaef5cce1372f9e8d6ec Mon Sep 17 00:00:00 2001
From: Rohit Aggarwal <Rohit.Aggarwal at amd.com>
Date: Mon, 7 Sep 2026 14:28:16 +0530
Subject: [PATCH 10/10] [clang] Pass -fast-library= to codegen TLI for
-ffastlib=
runCodeGenPipeline builds TLI from the LLVM -fast-library option, so the driver must forward AMDLIBM selection past the optimizer pipeline.
---
clang/lib/Driver/ToolChains/Clang.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index bc71a08332df46..44b6c24a7c2ac0 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6044,6 +6044,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
<< Name << Triple.getArchName();
}
A->render(Args, CmdArgs);
+ // Codegen TLI is built in runCodeGenPipeline from -fast-library=.
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back(Args.MakeArgString("-fast-library=" + Name));
}
if (Args.hasFlag(options::OPT_fmerge_all_constants,
More information about the cfe-commits
mailing list