diff options
author | Frederik Harwath <frederik.harwath@amd.com> | 2025-09-03 16:27:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-03 16:27:15 +0200 |
commit | 47793f9a73314a7669f436ee6e0528203c8633e7 (patch) | |
tree | fd97f7461872aa5fe0b75a4a908315af0fd617a4 /llvm/lib/Passes/PassBuilder.cpp | |
parent | d15998fe64619e1cc0d6285fbd24d5fe5429c9ef (diff) | |
download | llvm-47793f9a73314a7669f436ee6e0528203c8633e7.zip llvm-47793f9a73314a7669f436ee6e0528203c8633e7.tar.gz llvm-47793f9a73314a7669f436ee6e0528203c8633e7.tar.bz2 |
[AMDGPU] Implement IR expansion for frem instruction (#130988)
This patch implements a correctly rounded expansion of the frem
instruction in LLVM IR. This is useful for target architectures for
which such an expansion is too involved to be implement in ISel
Lowering. The expansion is based on the code from the AMD device libs
and has been tested successfully against the OpenCL conformance tests on
amdgpu. The expansion is implemented in the preexisting "expand-fp"
pass. It replaces the expansion of "frem" in ISel for the amdgpu target;
it is enabled for targets which do not directly support "frem" and for
which no matching "fmod" LibCall is available.
---------
Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
Diffstat (limited to 'llvm/lib/Passes/PassBuilder.cpp')
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index d75304b..587f0ec 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -185,6 +185,7 @@ #include "llvm/IR/Verifier.h" #include "llvm/IRPrinter/IRPrintingPasses.h" #include "llvm/Passes/OptimizationLevel.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -1492,6 +1493,29 @@ parseBoundsCheckingOptions(StringRef Params) { return Options; } +Expected<CodeGenOptLevel> parseExpandFpOptions(StringRef Params) { + if (Params.empty()) + return CodeGenOptLevel::None; + + StringRef Param; + std::tie(Param, Params) = Params.split(';'); + if (!Params.empty()) + return createStringError("too many expand-fp pass parameters"); + + auto [Name, Val] = Param.split('='); + if (Name != "opt-level") + return createStringError("invalid expand-fp pass parameter '%s'", + Param.str().c_str()); + int8_t N; + Val.getAsInteger(10, N); + std::optional<CodeGenOptLevel> Level = CodeGenOpt::getLevel(N); + if (!Level.has_value()) + return createStringError("invalid expand-fp opt-level value: %s", + Val.str().c_str()); + + return *Level; +} + Expected<RAGreedyPass::Options> parseRegAllocGreedyFilterFunc(PassBuilder &PB, StringRef Params) { if (Params.empty() || Params == "all") |