[PATCH] D102725: [SDAG] propagate FMF from target-specific IR intrinsics

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 18 14:05:32 PDT 2021


spatel created this revision.
spatel added reviewers: qiucf, craig.topper, Jim.
Herald added subscribers: pengfei, hiraditya, mcrosier.
spatel requested review of this revision.
Herald added a project: LLVM.

This is a step towards relying more on node-level FMF rather than function-wide or target settings. I think it was just an oversight that we didn't get this path in D87361 <https://reviews.llvm.org/D87361> or follow-on patches.

The lack of FMF propagation is blocking D90901 <https://reviews.llvm.org/D90901> from converting tests to IR-level FMF.

We can't do much more than this currently because we also fail to propagate flags from x86-specific node to generic FMA node. That would be another patch, so the test just verifies that we can transfer from IR to initial SDAG node.


https://reviews.llvm.org/D102725

Files:
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/X86/fmf-propagation.ll


Index: llvm/test/CodeGen/X86/fmf-propagation.ll
===================================================================
--- llvm/test/CodeGen/X86/fmf-propagation.ll
+++ llvm/test/CodeGen/X86/fmf-propagation.ll
@@ -48,8 +48,8 @@
 declare <16 x float> @llvm.x86.avx512.vfmadd.ps.512(<16 x float>, <16 x float>, <16 x float>, i32)
 
 ; CHECK-LABEL: Initial selection DAG: %bb.0 'fmf_target_intrinsic:'
-; CHECK: v16f32 = llvm.x86.avx512.vfmadd.ps.512 TargetConstant:i64<9546>
-; CHECK: v16f32 = llvm.x86.avx512.vfmadd.ps.512 TargetConstant:i64<9546>
+; CHECK: v16f32 = llvm.x86.avx512.vfmadd.ps.512 ninf nsz TargetConstant:i64<9546>
+; CHECK: v16f32 = llvm.x86.avx512.vfmadd.ps.512 nsz TargetConstant:i64<9546>
 
 define <16 x float> @fmf_target_intrinsic(<16 x float> %a, <16 x float> %b, <16 x float> %c) nounwind {
   %t0 = tail call ninf nsz <16 x float> @llvm.x86.avx512.vfmadd.ps.512(<16 x float> %a, <16 x float> %b, <16 x float> %c, i32 4)
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4803,6 +4803,12 @@
 
   SDVTList VTs = DAG.getVTList(ValueVTs);
 
+  // Propagate fast-math-flags from IR to node(s).
+  SDNodeFlags Flags;
+  if (auto *FPMO = dyn_cast<FPMathOperator>(&I))
+    Flags.copyFMF(*FPMO);
+  SelectionDAG::FlagInserter FlagsInserter(DAG, Flags);
+
   // Create the node.
   SDValue Result;
   if (IsTgtIntrinsic) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102725.346258.patch
Type: text/x-patch
Size: 1533 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/6d96cb7c/attachment.bin>


More information about the llvm-commits mailing list