@@ -2064,6 +2064,25 @@ SPIRVToLLVM::transConvertInst(SPIRVValue* BV, Function* F, BasicBlock* BB) {
2064
2064
return ConstantExpr::getCast (CO, dyn_cast<Constant>(Src), Dst);
2065
2065
}
2066
2066
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
+
2067
2086
BinaryOperator *SPIRVToLLVM::transShiftLogicalBitwiseInst (SPIRVValue* BV,
2068
2087
BasicBlock* BB,Function* F) {
2069
2088
SPIRVBinary* BBN = static_cast <SPIRVBinary*>(BV);
@@ -2085,6 +2104,7 @@ BinaryOperator *SPIRVToLLVM::transShiftLogicalBitwiseInst(SPIRVValue* BV,
2085
2104
Inst->setHasNoUnsignedWrap (true );
2086
2105
}
2087
2106
2107
+ applyFPFastMathModeDecorations (BV, Inst);
2088
2108
return Inst;
2089
2109
}
2090
2110
@@ -3181,15 +3201,17 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
3181
3201
3182
3202
case OpFNegate: {
3183
3203
SPIRVUnary *BC = static_cast <SPIRVUnary*>(BV);
3184
- return mapValue (BV,
3204
+ auto Neg =
3185
3205
#if LLVM_VERSION_MAJOR <= 10
3186
3206
BinaryOperator
3187
3207
#else
3188
3208
UnaryOperator
3189
3209
#endif
3190
3210
::CreateFNeg (
3191
3211
transValue (BC->getOperand (0 ), F, BB),
3192
- BV->getName(), BB));
3212
+ BV->getName(), BB);
3213
+ applyFPFastMathModeDecorations (BV, Neg);
3214
+ return mapValue(BV, Neg);
3193
3215
}
3194
3216
break ;
3195
3217
0 commit comments