Skip to content

Commit d48f6e1

Browse files
fda0pszymich
authored andcommitted
Disable unsafe sin & cos optimizations for compute
Don't apply fast math flags to selected math builtins. Disable module-wide unsafe math optimizations for compute Fix regressions in CustomUnsafeOptPass by propagating fast math flags to newly created fsub and fdiv instructions. Keep handling xor optimizations by using an old method of looking up module metadata for FastRelaxedMath flag.
1 parent 75ab08c commit d48f6e1

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

IGC/AdaptorOCL/UnifyIROCL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static void CommonOCLBasedPasses(
206206
pContext->metrics.CollectFunctions(pContext->getModule());
207207

208208
unify_opt_PreProcess(pContext);
209+
pContext->m_checkFastFlagPerInstructionInCustomUnsafeOptPass = true;
209210

210211
DumpLLVMIR(pContext, "beforeUnification");
211212

IGC/Compiler/CodeGenPublic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,10 @@ namespace IGC
962962
BVHInfo bvhInfo;
963963
// Immediate constant buffer promotion is enabled for all optimization except for Direct storage case
964964
bool m_disableICBPromotion = false;
965+
// Ignore per module fast math flag and use only per instruction fast math flags
966+
// Add few changes to CustomUnsafeOptPass related to fast flag propagation
967+
bool m_checkFastFlagPerInstructionInCustomUnsafeOptPass = false;
968+
965969
private:
966970
//For storing error message
967971
std::stringstream oclErrorMessage;

IGC/Compiler/CustomUnsafeOptPass.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ static bool allowUnsafeMathOpt(CodeGenContext* ctx, llvm::BinaryOperator& op)
9090
return true;
9191
}
9292

93+
// then check compiler options in metadata
94+
if (!ctx->m_checkFastFlagPerInstructionInCustomUnsafeOptPass &&
95+
ctx->getModuleMetaData()->compOpt.FastRelaxedMath)
96+
{
97+
return true;
98+
}
99+
93100
if (IGC_IS_FLAG_ENABLED(EnableFastMath))
94101
{
95102
return true;
@@ -1207,11 +1214,15 @@ bool CustomUnsafeOptPass::visitBinaryOperatorNegateMultiply(BinaryOperator& I)
12071214
// otherwise replace mul src0 with the negate
12081215
if (!replaced)
12091216
{
1210-
fmulInst->setOperand(0, copyIRFlags(BinaryOperator::CreateFSub(ConstantFP::get(fmulInst->getType(), 0), fmulInst->getOperand(0), "", fmulInst), &I));
1217+
BinaryOperator* fsub = BinaryOperator::CreateFSub(ConstantFP::get(fmulInst->getType(), 0), fmulInst->getOperand(0), "", fmulInst);
1218+
if (m_ctx->m_checkFastFlagPerInstructionInCustomUnsafeOptPass)
1219+
{
1220+
fsub = copyIRFlags(fsub, &I);
1221+
}
1222+
fmulInst->setOperand(0, fsub);
12111223

12121224
// DIExpression in debug variable instructions must be extended with additional DWARF opcode:
12131225
// DW_OP_neg
1214-
Value* fsub = fmulInst->getOperand(0);
12151226
if (auto fsubInstr = dyn_cast<Instruction>(fsub)) {
12161227
Value* fsubOp0 = fsubInstr->getOperand(1);
12171228
if (auto fsubOp0Instr = dyn_cast<Instruction>(fsubOp0)) {
@@ -1483,7 +1494,12 @@ bool CustomUnsafeOptPass::visitBinaryOperatorAddDiv(BinaryOperator& I)
14831494
{
14841495
if (faddInst->getOperand(i) == I.getOperand(1))
14851496
{
1486-
Value* div = copyIRFlags(BinaryOperator::CreateFDiv(faddInst->getOperand(1 - i), I.getOperand(1), "", faddInst), &I);
1497+
BinaryOperator* div = BinaryOperator::CreateFDiv(faddInst->getOperand(1 - i), I.getOperand(1), "", faddInst);
1498+
if (m_ctx->m_checkFastFlagPerInstructionInCustomUnsafeOptPass)
1499+
{
1500+
div = copyIRFlags(div, &I);
1501+
}
1502+
14871503
const DebugLoc& DL = faddInst->getDebugLoc();
14881504
if (Instruction* divInst = dyn_cast<Instruction>(div))
14891505
divInst->setDebugLoc(DL);

0 commit comments

Comments
 (0)