This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Extend handlng of fp min/max.
ClosedPublic

Authored by skatkov on Mar 29 2023, 4:00 AM.

Details

Summary

Add support the cases like

m(m(X,Y),m'(X,Y)) => m(X,Y)

where m is one of maxnum, minnum, maximum, minimum and m' is m or inverse of m.

alive2 correctness check:
maxnum(maxnum,maxnum) https://alive2.llvm.org/ce/z/kSyAzo
maxnum(maxnum,minnum) https://alive2.llvm.org/ce/z/Vra8j2
minnum(minnum,minnum) https://alive2.llvm.org/ce/z/B6h-hW
minnum(minnum,maxnum) https://alive2.llvm.org/ce/z/rG2u_b
maximum(maximum,maximum) https://alive2.llvm.org/ce/z/N2nevY
maximum(maximum,minimum) https://alive2.llvm.org/ce/z/23RFcP
minimum(minimum,minimum) https://alive2.llvm.org/ce/z/spHZ-U
minimum(minimum,maximum) https://alive2.llvm.org/ce/z/Aa-VE8

Diff Detail

Event Timeline

skatkov created this revision.Mar 29 2023, 4:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 4:00 AM
skatkov requested review of this revision.Mar 29 2023, 4:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 4:00 AM
skatkov added inline comments.Mar 29 2023, 4:07 AM
llvm/lib/Analysis/ValueTracking.cpp
7164

The documentation for this method does not say whether "inverse" expects that if a != b then max(a, b) != min(a, b).
For new added cases it is not true.

So if it is expected I can create another utility function.

skatkov updated this revision to Diff 510996.Apr 4 2023, 10:35 PM
skatkov retitled this revision from Extend handlng of fp min/max. to [InstSimplify] Extend handlng of fp min/max..
skatkov edited the summary of this revision. (Show Details)

Pre-land tests, update description with alive2 checks.

RKSimon added inline comments.Apr 5 2023, 1:40 AM
llvm/lib/Analysis/InstructionSimplify.cpp
6128

assert that IID is one of the min/max intrinsic IDs?

skatkov updated this revision to Diff 511019.Apr 5 2023, 1:55 AM
skatkov marked an inline comment as done.
RKSimon added inline comments.Apr 6 2023, 1:25 PM
llvm/lib/Analysis/InstructionSimplify.cpp
6130

(style) add assertion message

skatkov updated this revision to Diff 511621.Apr 6 2023, 11:11 PM
skatkov marked an inline comment as done.
RKSimon added inline comments.Apr 18 2023, 5:14 AM
llvm/test/Transforms/InstSimplify/fminmax-folds.ll
1201–1385

Maybe convert a few of these existing tests to take other float types / vectors ? I don't think there's a need to duplicate patterns - just have more type variety.

skatkov updated this revision to Diff 514829.Apr 18 2023, 11:23 PM

Tests are updated, please take a look.

skatkov marked an inline comment as done.Apr 18 2023, 11:24 PM

Can I do anything more here?

dantrushin accepted this revision.Apr 25 2023, 7:39 AM

LGTM.
Please wait couple days in case @RKSimon has some more comments/concerns

This revision is now accepted and ready to land.Apr 25 2023, 7:39 AM
RKSimon accepted this revision.Apr 26 2023, 3:53 AM

LGTM with one minor

llvm/lib/Analysis/ValueTracking.cpp
7164

No need - but add a comment explaining this for these cases

This revision was landed with ongoing or failed builds.Apr 26 2023, 8:46 PM
This revision was automatically updated to reflect the committed changes.