[llvm] [InstCombine] Ensure Safe Handling of Flags in foldFNegIntoConstant (PR #94148)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 13:04:16 PDT 2024


================
@@ -2741,6 +2741,17 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
   return TryToNarrowDeduceFlags();
 }
 
+static FastMathFlags combineFastMathFlagsForFNeg(FastMathFlags FMF,
+                                                 FastMathFlags OpFMF) {
+  FastMathFlags Flag = FMF | OpFMF;
+  Flag.setNoInfs(FMF.noInfs() && OpFMF.noInfs());
+  Flag.setAllowReassoc(FMF.allowReassoc() && OpFMF.allowReassoc());
+  Flag.setApproxFunc(FMF.approxFunc() && OpFMF.approxFunc());
+  Flag.setAllowReciprocal(FMF.allowReciprocal() && OpFMF.allowReciprocal());
+  Flag.setAllowContract(FMF.allowContract() && OpFMF.allowContract());
+  return Flag;
+}
----------------
arsenm wrote:

We should have an | value flag & rewrite flag helper in FastMathFlags but can do API cleanups later 

https://github.com/llvm/llvm-project/pull/94148


More information about the llvm-commits mailing list