[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

Phoebe Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 21 01:09:33 PST 2022


pengfei created this revision.
pengfei added reviewers: RKSimon, arsenm.
Herald added a project: All.
pengfei requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

@arsenm raised a good question that we should use a flag guard.
But I found it is not a problem as long as user uses intrinsics only: https://godbolt.org/z/WoYsqqjh3
Anyway, it is still nice to have.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140467

Files:
  clang/lib/CodeGen/CGBuiltin.cpp


Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -14737,8 +14737,11 @@
   case X86::BI__builtin_ia32_reduce_fadd_ph128: {
     Function *F =
         CGM.getIntrinsic(Intrinsic::vector_reduce_fadd, Ops[1]->getType());
+    FastMathFlags FMF = Builder.getFastMathFlags();
     Builder.getFastMathFlags().setAllowReassoc();
-    return Builder.CreateCall(F, {Ops[0], Ops[1]});
+    Value *FAdd = Builder.CreateCall(F, {Ops[0], Ops[1]});
+    Builder.getFastMathFlags() &= (FMF);
+    return FAdd;
   }
   case X86::BI__builtin_ia32_reduce_fmul_pd512:
   case X86::BI__builtin_ia32_reduce_fmul_ps512:
@@ -14747,8 +14750,11 @@
   case X86::BI__builtin_ia32_reduce_fmul_ph128: {
     Function *F =
         CGM.getIntrinsic(Intrinsic::vector_reduce_fmul, Ops[1]->getType());
+    FastMathFlags FMF = Builder.getFastMathFlags();
     Builder.getFastMathFlags().setAllowReassoc();
-    return Builder.CreateCall(F, {Ops[0], Ops[1]});
+    Value *FMul = Builder.CreateCall(F, {Ops[0], Ops[1]});
+    Builder.getFastMathFlags() &= (FMF);
+    return FMul;
   }
   case X86::BI__builtin_ia32_reduce_fmax_pd512:
   case X86::BI__builtin_ia32_reduce_fmax_ps512:
@@ -14757,8 +14763,11 @@
   case X86::BI__builtin_ia32_reduce_fmax_ph128: {
     Function *F =
         CGM.getIntrinsic(Intrinsic::vector_reduce_fmax, Ops[0]->getType());
+    FastMathFlags FMF = Builder.getFastMathFlags();
     Builder.getFastMathFlags().setNoNaNs();
-    return Builder.CreateCall(F, {Ops[0]});
+    Value *FMax = Builder.CreateCall(F, {Ops[0]});
+    Builder.getFastMathFlags() &= (FMF);
+    return FMax;
   }
   case X86::BI__builtin_ia32_reduce_fmin_pd512:
   case X86::BI__builtin_ia32_reduce_fmin_ps512:
@@ -14767,8 +14776,11 @@
   case X86::BI__builtin_ia32_reduce_fmin_ph128: {
     Function *F =
         CGM.getIntrinsic(Intrinsic::vector_reduce_fmin, Ops[0]->getType());
+    FastMathFlags FMF = Builder.getFastMathFlags();
     Builder.getFastMathFlags().setNoNaNs();
-    return Builder.CreateCall(F, {Ops[0]});
+    Value *FMin = Builder.CreateCall(F, {Ops[0]});
+    Builder.getFastMathFlags() &= (FMF);
+    return FMin;
   }
 
   // 3DNow!


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140467.484492.patch
Type: text/x-patch
Size: 2260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221221/d8ab7efb/attachment.bin>


More information about the cfe-commits mailing list