This is an archive of the discontinued LLVM Phabricator instance.

[SLP] match maxnum/minnum intrinsics as FP reduction ops
ClosedPublic

Authored by spatel on Jan 18 2021, 6:59 AM.

Details

Summary

After much refactoring over the last 2 weeks to the reduction matching code, I think this change is finally ready.
We effectively broke fmax/fmin vector reduction optimization when we started canonicalizing to intrinsics in instcombine, so this will hopefully restore that for SLP.
There are still FMF problems here as noted in the code comments, but we should be avoiding miscompiles on those for fmax/fmin by restricting to full 'fast' ops (negative tests are included). I am planning to look at fixing FMF propagation next.
There's also an open cost model question: should we prefer the getIntrinsicInstrCost() API (as is currently shown in the patch) or use getMinMaxReductionCost() (as is currently shown for the integer min/max ops)? There are no test differences with the current regression tests, but that will need to be examined in more detail to make sure we are getting accurate costs.

Diff Detail

Event Timeline

spatel created this revision.Jan 18 2021, 6:59 AM
spatel requested review of this revision.Jan 18 2021, 6:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2021, 6:59 AM
spatel updated this revision to Diff 317353.Jan 18 2021, 7:31 AM
spatel edited the summary of this revision. (Show Details)

Patch updated: I changed some variable names with d1c4e85 and missed rebasing this diff.

ABataev added inline comments.Jan 18 2021, 8:51 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
7106–7108

Probably better to use getMinMaxReductionCost rather than the cost of the intrinsic call, it is more precise.

spatel added inline comments.Jan 18 2021, 9:19 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
7106–7108

Ok - I'll update. The current patch is actually wrong because I did not use the correct reduction IDs (Intrinsic::vector_reduce_fmax) for the vector cost.

spatel updated this revision to Diff 317380.Jan 18 2021, 9:38 AM

Patch updated:

  1. Change cost calc to use getMinMaxReductionCost() (this is copied from the existing integer min/max code).
  2. Added test coverage/comments to demonstrate FMF constraints.
This revision is now accepted and ready to land.Jan 18 2021, 11:02 AM
This revision was automatically updated to reflect the committed changes.