Skip to content

Commit

Permalink
[DAGCombiner] Do not fold fadd (fmul x, y), (fmul x, y) -> fma x, y, …
Browse files Browse the repository at this point in the history
…(fmul x, y)

Differential Revision: https://reviews.llvm.org/D151890
  • Loading branch information
jayfoad committed Jun 1, 2023
1 parent 5952664 commit b7052fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 7 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Expand Up @@ -15233,6 +15233,13 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
if (!AllowFusionGlobally && !N->getFlags().hasAllowContract())
return SDValue();

// Folding fadd (fmul x, y), (fmul x, y) -> fma x, y, (fmul x, y) is never
// beneficial. It does not reduce latency. It increases register pressure. It
// replaces an fadd with an fma which is a more complex instruction, so is
// likely to have a larger encoding, use more functional units, etc.
if (N0 == N1)
return SDValue();

if (TLI.generateFMAsInMachineCombiner(VT, OptLevel))
return SDValue();

Expand Down
4 changes: 1 addition & 3 deletions llvm/test/CodeGen/AMDGPU/dagcombine-fma-fmad.ll
Expand Up @@ -277,9 +277,7 @@ define amdgpu_ps float @fma_vs_output_modifier(float %x, i32 %n) #0 {
define amdgpu_ps float @fma_vs_output_modifier_2(float %x) #0 {
; GCN-LABEL: fma_vs_output_modifier_2:
; GCN: ; %bb.0:
; GCN-NEXT: v_mul_f32_e32 v1, v0, v0
; GCN-NEXT: v_fmac_f32_e32 v1, v0, v0
; GCN-NEXT: v_mov_b32_e32 v0, v1
; GCN-NEXT: v_mul_f32_e64 v0, v0, v0 mul:2
; GCN-NEXT: ; return to shader part epilog
%m = fmul contract float %x, %x
%a = fadd nsz contract float %m, %m
Expand Down

0 comments on commit b7052fa

Please sign in to comment.