This is an archive of the discontinued LLVM Phabricator instance.

[mlir][math]Expand Fused math.fmaf to a multiply-add
ClosedPublic

Authored by bviyer on Apr 7 2023, 2:02 PM.

Details

Summary

Fused multiply and add are being pushed directly to the libm. This is problematic
for situations where libm is not available. This patch will break down a fused multiply and
add into a multiply followed by an add.

Diff Detail

Event Timeline

bviyer created this revision.Apr 7 2023, 2:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2023, 2:02 PM
bviyer requested review of this revision.Apr 7 2023, 2:02 PM
rsuderman added inline comments.Apr 7 2023, 2:09 PM
mlir/test/Dialect/Math/expand-math.mlir
71

I would not include the CHECK-NOT, if we are matching the replacement we just assume the old op is gone.

72

[[NAME:%.+]] is used to capture a new variable
[[NAME]] is used to reference a previously captured one

Also, we typically avoid capture the % in the matcher. It seems arbitrary but there are certain cases where it makes the test easier to write. Also make sure the capture named makes sense (e.g. MULF). You can also drop types from the verifier and if they are inferred from the parent.

For short, this check should look like

// CHECK-NEXT:     [[MULF:%.+]] = arith.mulf %[[ARG0]], %[[ARG1]]

Repeat for the following lines.

bviyer updated this revision to Diff 511799.Apr 7 2023, 2:36 PM

Added the changes requested by rsuderman

bviyer marked 2 inline comments as done.Apr 7 2023, 2:41 PM

@rsuderman: I have fixed the changes you have requested.

rsuderman retitled this revision from [mlir][math]Expand Fused multiply and accumulate to a multiply followed by an add for FP64 operations. to [mlir][math]Expand Fused math.fmaf to a multiply-add.Apr 7 2023, 2:46 PM
rsuderman accepted this revision.Apr 7 2023, 3:10 PM
This revision is now accepted and ready to land.Apr 7 2023, 3:10 PM