[PATCH] D31168: Set FMF for -ffp-contract=fast rather than a TargetConfig

Adam Nemet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 20:12:55 PDT 2017


anemet created this revision.

This is toward moving fp-contraction=fast from an LLVM TargetOption to a
FastMathFlag in order to fix PR25721.


https://reviews.llvm.org/D31168

Files:
  lib/CodeGen/CGExprScalar.cpp


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<BinaryOperator>(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<ScalarExprEmitter, Value*>::Visit(E);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31168.92424.patch
Type: text/x-patch
Size: 1037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170321/4fd53c31/attachment.bin>


More information about the cfe-commits mailing list