[llvm] [AMDGPU] Implement IR variant of isFMAFasterThanFMulAndFAdd (PR #121465)

Petar Avramovic via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 24 08:36:17 PDT 2025


petar-avramovic wrote:

Hi, this is causing performance regressions because large blocks of same code in if and else are not hoisted.
What happens is that fmul has user that is fadd, and instead of hoisting both we stop there. This also prevents any instructions below to be hoisted.
I wrote small test similar to the ones in this patch:
```
define amdgpu_ps float @hoist(float %cnd, float %a, float %b, float %c, float %d, float %e) #0 {
entry:
  %cmp = fcmp oeq float %cnd, 0.000000e+00
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  %mul_hoist_if_1 = fmul contract float %a, %b
  %add_hoist_if_1 = fadd contract float %mul_hoist_if_1, %c
  %dependant_hoist_if = fdiv contract float %add_hoist_if_1, %d
  %add = fadd contract float 1.000000e+00, %dependant_hoist_if
  ret float %add

if.else:                                          ; preds = %entry
  %mul_hoist_else_1 = fmul contract float %a, %b
  %add_hoist_else_1 = fadd contract float %mul_hoist_else_1, %c
  %dependant_hoist_else = fdiv contract float %add_hoist_else_1, %d
  %sub = fsub contract float %dependant_hoist_else, %add_hoist_else_1
  %mul = fmul contract float %add_hoist_else_1, %sub
  ret float %mul
}
```
Three instructions should be hoisted.
The flaw in this patch is that it does not know if simplifycfg wants to hoist `User`
- if yes hoist both fmul and `User`
- in no this patch
but it seems to require some change in llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Can we revert this for now?




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


More information about the llvm-commits mailing list