Skip to content

Commit 7d73b04

Browse files
aratajewigcbot
authored andcommitted
Respect per instruction contraction flag in mad pattern match.
SPV_INTEL_fp_fast_math_mode introduces AllowContractFastINTEL fast math flag. When instruction is decorated with this flag, contractions are allowed even if it may violate language standard. This enum maps to LLVM fast math flags, but was not respected in "mad" instruction pattern match.
1 parent 34f4fb0 commit 7d73b04

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

IGC/AdaptorOCL/DriverInfoOCL.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ namespace TC
7575
bool NeedFP64DivSqrt() const override { return true; }
7676

7777
bool EnableIntegerMad() const override { return true; }
78+
79+
bool RespectPerInstructionContractFlag() const override { return true; }
7880
};
7981

8082
// In case some cpas are specific to NEO

IGC/Compiler/CISACodeGen/DriverInfo.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ namespace IGC
286286
/// Check if integer mad is enabled
287287
virtual bool EnableIntegerMad() const { return false; }
288288

289+
/// Respect per instruction 'contract' Fast-Math flag
290+
virtual bool RespectPerInstructionContractFlag() const { return false; }
291+
289292
/// add shader hash code after EOT for debug purposes
290293
virtual bool EnableShaderDebugHashCodeInKernel() const { return false; }
291294

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,9 +2030,18 @@ namespace IGC
20302030
{
20312031
return false;
20322032
}
2033+
2034+
bool isFpMadWithContractionOverride = false;
20332035
if (isFpMad(I) && m_AllowContractions == false)
20342036
{
2035-
return false;
2037+
if (I.hasAllowContract() && m_ctx->m_DriverInfo.RespectPerInstructionContractFlag())
2038+
{
2039+
isFpMadWithContractionOverride = true;
2040+
}
2041+
else
2042+
{
2043+
return false;
2044+
}
20362045
}
20372046
if (!isFpMad(I) && !(m_Platform.doIntegerMad() && m_ctx->m_DriverInfo.EnableIntegerMad()))
20382047
{
@@ -2072,6 +2081,10 @@ namespace IGC
20722081
// in case we know we won't be able to remove the mul we don't merge it
20732082
if (!m_PosDep->PositionDependsOnInst(mul) && NeedInstruction(*mul))
20742083
continue;
2084+
2085+
if (isFpMadWithContractionOverride && !mul->hasAllowContract())
2086+
continue;
2087+
20752088
sources[2] = I.getOperand(1 - i);
20762089
sources[1] = mul->getOperand(0);
20772090
sources[0] = mul->getOperand(1);

0 commit comments

Comments
 (0)