This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add support for max(a,b) + min(a,b) => a + b.
ClosedPublic

Authored by skatkov on Mar 30 2023, 8:50 PM.

Diff Detail

Event Timeline

skatkov created this revision.Mar 30 2023, 8:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 8:50 PM
skatkov requested review of this revision.Mar 30 2023, 8:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 8:50 PM
skatkov updated this revision to Diff 509895.Mar 30 2023, 9:14 PM

remove redundant m_c to safe a compile time a bit.

Please add alive2 links for the proofs for {mul, add} x {smin/smax, umin/umax}.

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
1596

Can you move this to before nuw/nsw flags are set (L1557).

1602

I think you can also preserve nuw and nsw flags.
https://alive2.llvm.org/ce/z/EaiNjB

likewise in the mul case:
https://alive2.llvm.org/ce/z/sV3tnG

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
486

Can you move this before I is potentially modified and Changed is set (before L474).

llvm/test/Transforms/InstCombine/add-min-max.ll
2

Can you split the tests into a seperate patch so we can see the diff this patch results in?

llvm/test/Transforms/InstCombine/mul-min-max.ll
10

This (along with other tests) are misnamed. ('add' -> 'mul')

skatkov updated this revision to Diff 509939.Mar 31 2023, 1:23 AM
skatkov edited the summary of this revision. (Show Details)

Thank you very much for review.

skatkov marked 5 inline comments as done.Mar 31 2023, 1:24 AM
goldstein.w.n accepted this revision.Apr 4 2023, 7:33 PM

LGTM.

I'm not a maintainer so give it a day or so before pushing so others have a chance to look it over if they want.

This revision is now accepted and ready to land.Apr 4 2023, 7:33 PM

LGTM.

I'm not a maintainer so give it a day or so before pushing so others have a chance to look it over if they want.

Sure, Thank a lot for review.

skatkov updated this revision to Diff 510988.Apr 4 2023, 8:36 PM

NFC update - use of BinaryOperator::CreateWithCopiedFlags utility instead of manually copying flags.

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