Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -256,8 +256,22 @@ // Visitor Methods //===--------------------------------------------------------------------===// + /// A RAII to apply the FP features from the expression to the IRBuilder. + struct ApplyFPFeatures : public CGBuilderTy::FastMathFlagGuard { + ApplyFPFeatures(llvm::IRBuilderBase &Builder, Expr *E) + : CGBuilderTy::FastMathFlagGuard(Builder) { + if (const auto *BO = dyn_cast(E)) { + llvm::FastMathFlags FMF = Builder.getFastMathFlags(); + FMF.setAllowContract( + BO->getFPFeatures().allowFPContractAcrossStatement()); + Builder.setFastMathFlags(FMF); + } + } + }; + Value *Visit(Expr *E) { ApplyDebugLocation DL(CGF, E); + ApplyFPFeatures FPF(Builder, E); return StmtVisitor::Visit(E); }