Skip to content

Commit 47793f9

Browse files
frederik-harsenm
andauthored
[AMDGPU] Implement IR expansion for frem instruction (llvm#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 <[email protected]>
1 parent d15998f commit 47793f9

File tree

19 files changed

+20710
-4013
lines changed

19 files changed

+20710
-4013
lines changed

llvm/include/llvm/CodeGen/ExpandFp.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_CODEGEN_EXPANDFP_H
1111

1212
#include "llvm/IR/PassManager.h"
13+
#include "llvm/Support/CodeGen.h"
1314

1415
namespace llvm {
1516

@@ -18,11 +19,15 @@ class TargetMachine;
1819
class ExpandFpPass : public PassInfoMixin<ExpandFpPass> {
1920
private:
2021
const TargetMachine *TM;
22+
CodeGenOptLevel OptLevel;
2123

2224
public:
23-
explicit ExpandFpPass(const TargetMachine *TM_) : TM(TM_) {}
25+
explicit ExpandFpPass(const TargetMachine *TM, CodeGenOptLevel OptLevel);
2426

2527
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
28+
29+
void printPipeline(raw_ostream &OS,
30+
function_ref<StringRef(StringRef)> MapClassName2PassName);
2631
};
2732

2833
} // end namespace llvm

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ LLVM_ABI FunctionPass *createCFIFixup();
550550
/// Creates CFI Instruction Inserter pass. \see CFIInstrInserter.cpp
551551
LLVM_ABI FunctionPass *createCFIInstrInserter();
552552

553+
// Expands floating point instructions.
554+
FunctionPass *createExpandFpPass(CodeGenOptLevel);
555+
553556
/// Creates CFGuard longjmp target identification pass.
554557
/// \see CFGuardLongjmp.cpp
555558
LLVM_ABI FunctionPass *createCFGuardLongjmpPass();

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addISelPasses(
737737

738738
addPass(PreISelIntrinsicLoweringPass(&TM));
739739
addPass(ExpandLargeDivRemPass(&TM));
740-
addPass(ExpandFpPass(&TM));
740+
addPass(ExpandFpPass(&TM, getOptLevel()));
741741

742742
derived().addIRPasses(addPass);
743743
derived().addCodeGenPrepare(addPass);

0 commit comments

Comments
 (0)