[DivRemPairs] Recommit: Handling for expanded-form rem - recomposition (PR42673)
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 31 Jul 2019 12:06:51 +0000 (12:06 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 31 Jul 2019 12:06:51 +0000 (12:06 +0000)
commita686c60c45d516cc8870b77af97fa66e3578807d
treeb158455439964c51d42501f5eb53a60cf4850086
parenta9d58436af83eeeca376a0686bb13fc43d3f8ece
[DivRemPairs] Recommit: Handling for expanded-form rem - recomposition (PR42673)

Summary:
While `-div-rem-pairs` pass can decompose rem in div+rem pair when div-rem pair
is unsupported by target, nothing performs the opposite fold.
We can't do that in InstCombine or DAGCombine since neither of those has access to TTI.
So it makes most sense to teach `-div-rem-pairs` about it.

If we matched rem in expanded form, we know we will be able to place div-rem pair
next to each other so we won't regress the situation.
Also, we shouldn't decompose rem if we matched already-decomposed form.
This is surprisingly straight-forward otherwise.

The original patch was committed in rL367288 but was reverted in rL367289
because it exposed pre-existing RAUW issues in internal data structures
of the pass; those now have been addressed in a previous patch.

https://bugs.llvm.org/show_bug.cgi?id=42673

Reviewers: spatel, RKSimon, efriedma, ZaMaZaN4iK, bogner

Reviewed By: bogner

Subscribers: bogner, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65298

llvm-svn: 367419
llvm/include/llvm/Transforms/Utils/BypassSlowDivision.h
llvm/lib/Transforms/Scalar/DivRemPairs.cpp
llvm/test/Transforms/DivRemPairs/X86/div-expanded-rem-pair.ll
llvm/test/Transforms/DivRemPairs/X86/div-rem-pairs.ll