/
redgpu
/
ispc
Обзор
Документация
Войти
/
redgpu
/
ispc
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/opt/FastMath.cpp
73 строки
2 KB
Jérôme Richard
Make fast-math optimizations more aggressive (#3489)
18 мар 2026, 07:20
Не верифицирован
18 мар 2026, 07:20
1921a43
Код
Авторство
О чём код?
/* Copyright (c) 2026, Intel Corporation SPDX-License-Identifier: BSD-3-Clause */ #include "FastMath.h" #include "builtins-decl.h" namespace ispc { bool FastMathPass::optimizeFpInstructions(llvm::BasicBlock &bb) { DEBUG_START_BB("FastMath"); bool modifiedAny = false; llvm::FastMathFlags fmFlags; if (g->opt.fastMath == Opt::FastMathMode::Balanced) { // Note that imprecise rcp instructions are apparently only generated // when at least both math function approximations and reciprocal are // allowed. fmFlags.setAllowContract(true); fmFlags.setAllowReassoc(true); fmFlags.setNoSignedZeros(true); fmFlags.setAllowReciprocal(true); } else if (g->opt.fastMath == Opt::FastMathMode::Aggressive) { // This improves the performance of generated codes in some cases but // it is much more dangerous. Indeed, it assumes there are no NaN, // infinities, negative zeros or subnormal values computed by the // target code. If this assumption is broken, then LLVM stores poison // values in the output so the target code basically has an undefined // behaviour and may do completely crazy things (very hard to debug // for ISPC users). For more information, please read: // https://github.com/iree-org/iree/issues/19743 fmFlags.setFast(true); } // Note: we do modify instruction list during the traversal, so the iterator // is moved forward before the instruction is processed. for (llvm::BasicBlock::iterator iter = bb.begin(), e = bb.end(); iter != e;) { llvm::BasicBlock::iterator curIter = iter++; llvm::Instruction *inst = &*curIter; if (llvm::dyn_cast<llvm::FPMathOperator>(inst)) { inst->setFastMathFlags(fmFlags); modifiedAny = true; } } DEBUG_END_BB("FastMath"); return modifiedAny; } llvm::PreservedAnalyses FastMathPass::run(llvm::Function &F, llvm::FunctionAnalysisManager &FAM) { llvm::TimeTraceScope FuncScope("FastMathPass::run", F.getName()); bool modifiedAny = false; for (llvm::BasicBlock &BB : F) { modifiedAny |= optimizeFpInstructions(BB); } if (!modifiedAny) { // No changes, all analyses are preserved. return llvm::PreservedAnalyses::all(); } llvm::PreservedAnalyses PA; PA.preserveSet<llvm::CFGAnalyses>(); return PA; } } // namespace ispc