Skip to content

Commit 176dde6

Browse files
grey-eminenceigcbot
authored andcommitted
Add translation of FPFastMathMode decorations in SPIRVReader. This is a port of KhronosGroup/SPIRV-LLVM-Translator@14e2c5f (2nd try). (#32)
1 parent ba89228 commit 176dde6

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,25 @@ SPIRVToLLVM::transConvertInst(SPIRVValue* BV, Function* F, BasicBlock* BB) {
20642064
return ConstantExpr::getCast(CO, dyn_cast<Constant>(Src), Dst);
20652065
}
20662066

2067+
static void applyFPFastMathModeDecorations(const SPIRVValue* BV,
2068+
Instruction* Inst) {
2069+
SPIRVWord V;
2070+
FastMathFlags FMF;
2071+
if (BV->hasDecorate(DecorationFPFastMathMode, 0, &V)) {
2072+
if (V & FPFastMathModeNotNaNMask)
2073+
FMF.setNoNaNs();
2074+
if (V & FPFastMathModeNotInfMask)
2075+
FMF.setNoInfs();
2076+
if (V & FPFastMathModeNSZMask)
2077+
FMF.setNoSignedZeros();
2078+
if (V & FPFastMathModeAllowRecipMask)
2079+
FMF.setAllowReciprocal();
2080+
if (V & FPFastMathModeFastMask)
2081+
FMF.setFast();
2082+
Inst->setFastMathFlags(FMF);
2083+
}
2084+
}
2085+
20672086
BinaryOperator *SPIRVToLLVM::transShiftLogicalBitwiseInst(SPIRVValue* BV,
20682087
BasicBlock* BB,Function* F) {
20692088
SPIRVBinary* BBN = static_cast<SPIRVBinary*>(BV);
@@ -2085,6 +2104,7 @@ BinaryOperator *SPIRVToLLVM::transShiftLogicalBitwiseInst(SPIRVValue* BV,
20852104
Inst->setHasNoUnsignedWrap(true);
20862105
}
20872106

2107+
applyFPFastMathModeDecorations(BV, Inst);
20882108
return Inst;
20892109
}
20902110

@@ -3181,15 +3201,17 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
31813201

31823202
case OpFNegate: {
31833203
SPIRVUnary *BC = static_cast<SPIRVUnary*>(BV);
3184-
return mapValue(BV,
3204+
auto Neg =
31853205
#if LLVM_VERSION_MAJOR <= 10
31863206
BinaryOperator
31873207
#else
31883208
UnaryOperator
31893209
#endif
31903210
::CreateFNeg(
31913211
transValue(BC->getOperand(0), F, BB),
3192-
BV->getName(), BB));
3212+
BV->getName(), BB);
3213+
applyFPFastMathModeDecorations(BV, Neg);
3214+
return mapValue(BV, Neg);
31933215
}
31943216
break;
31953217

0 commit comments

Comments
 (0)