This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Canonicalize fast fmuladd to fmul + fadd
ClosedPublic

Authored by arsenm on Jan 7 2017, 12:25 PM.

Details

Reviewers
hfinkel

Diff Detail

Event Timeline

arsenm updated this revision to Diff 83533.Jan 7 2017, 12:25 PM
arsenm retitled this revision from to InstCombine: Do unsafe math combine of fadd + fmuladd + fmul.
arsenm updated this object.
arsenm added a subscriber: llvm-commits.

Under what circumstances do we create a 'fast' fmuladd. Maybe we should canonicalize a 'fast' fmuladd into a 'fast' mul and a 'fast' add instead?

lib/Transforms/InstCombine/InstCombineAddSub.cpp
434 ↗(On Diff #83533)

You're missing a closing ) in the first expression.

test/Transforms/InstCombine/fmuladd-opt.ll
2 ↗(On Diff #83533)

Missing closing ) here too.

Under what circumstances do we create a 'fast' fmuladd. Maybe we should canonicalize a 'fast' fmuladd into a 'fast' mul and a 'fast' add instead?

Clang emits this for a * b + c with -ffast-math -ffp-contract=on

Under what circumstances do we create a 'fast' fmuladd. Maybe we should canonicalize a 'fast' fmuladd into a 'fast' mul and a 'fast' add instead?

Clang emits this for a * b + c with -ffast-math -ffp-contract=on

Interesting. As implemented -ffast-math implies -ffp-contract=fast:

const TargetOptions &Options = DAG.getTarget().Options;
bool AllowFusion =
    (Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath);

I think that we should:

  1. Have -ffast-math imply -ffp-contract=fast in Clang.

and/or

  1. Canonicalize fast fmuladd into fast mul + fast add.
arsenm updated this revision to Diff 88659.Feb 15 2017, 11:21 PM
arsenm retitled this revision from InstCombine: Do unsafe math combine of fadd + fmuladd + fmul to InstCombine: Canonicalize fast fmuladd to fmul + fadd.
arsenm edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Feb 15 2017, 11:29 PM
arsenm closed this revision.Feb 16 2017, 10:58 AM

r295353