This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] More opportunities to fuse fmul and fadd to fma aggressively
AbandonedPublic

Authored by slydiman on Sep 2 2022, 2:27 PM.

Details

Summary

This patch is adding a new pattern matching in DAGCombiner to look for opportunities to fuse fmul and fadd to fma aggressively.

The matching is very specific to the following pattern:
  FADD X, (FMA A, B, (FMA C, D, (MUL Y, Z)))
can be converted to
  FMA Y, Z (FMA A, B, (FMA C, D, X))

This transformation is also changing the orders of operations, so it will only be enabled for FADD, when it's fast-math attribute has reassoc or contract flag enabled.

Diff Detail

Event Timeline

slydiman created this revision.Sep 2 2022, 2:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2022, 2:27 PM
slydiman requested review of this revision.Sep 2 2022, 2:27 PM
slydiman updated this revision to Diff 458094.Sep 5 2022, 9:55 PM
tra added a comment.Sep 15 2022, 12:18 PM

I've been burned by FP numerics in the past, so I'm pretty sure I'm not qualified to tell whether the change will break something in an unexpected way.

FADD X, (FMA A, B, (FMA C, D, (MUL Y, Z))) -> FMA Y, Z (FMA A, B, (FMA C, D, X))

I'm curious, is there a reason for this particular arrangement? Are there any benefits/disadvantages vs, let's say FMA A, B (FMA C, D, (FMA Y, Z, X)) ?

slydiman abandoned this revision.Oct 2 2022, 3:42 PM

It seems already implemented here https://reviews.llvm.org/D132837