On Mon, Jul 27, 2015 at 12:23 PM, Bin.Cheng <amker.ch...@gmail.com> wrote: > On Mon, Jul 27, 2015 at 11:41 AM, Michael Collison > <michael.colli...@linaro.org> wrote: >> This patch is designed to optimize end of loop conditions involving of the >> form >> i < x && i < y into i < min (x, y). Loop condition involving '>' are >> handled similarly using max(x,y). >> As an example: >> >> #define N 1024 >> >> int a[N], b[N], c[N]; >> >> void add (unsignedint m, unsignedint n) >> { >> unsignedint i, bound = (m < n) ? m : n; >> for (i = 0; i < m && i < n; ++i) >> a[i] = b[i] + c[i]; >> } >> >> >> Performed bootstrap and make check on: x86_64_unknown-linux-gnu, >> arm-linux-gnueabihf, and aarch64-linux-gnu. >> Okay for trunk? >> >> 2015-07-24 Michael Collison <michael.colli...@linaro.org> >> Andrew Pinski <andrew.pin...@caviumnetworks.com> >> >> * match.pd ((x < y) && (x < z) -> x < min (y,z), >> (x > y) and (x > z) -> x > max (y,z)) >> >> diff --git a/gcc/match.pd b/gcc/match.pd >> index 5e8fd32..8691710 100644 >> --- a/gcc/match.pd >> +++ b/gcc/match.pd >> @@ -1793,3 +1793,17 @@ along with GCC; see the file COPYING3. If not see >> (convert (bit_and (op (convert:utype @0) (convert:utype @1)) >> (convert:utype @4))))))) >> >> + >> +/* Transform (@0 < @1 and @0 < @2) to use min */ >> +(for op (lt le) >> +(simplify >> +(bit_and:c (op @0 @1) (op @0 @2)) >> +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) >> +(op @0 (min @1 @2))))) >> + >> +/* Transform (@0 > @1 and @0 > @2) to use max */ >> +(for op (gt ge) >> +(simplify >> +(bit_and:c (op @0 @1) (op @0 @2)) >> +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) >> +(op @0 (max @1 @2))))) > > Could you please give a test case for it? Also IIUC, this is not only > simplification, but also loop invariant hoist, so how does it check > invariantness?
Sorry I realized this patch only does simplification and then let lim pass decide if it can be moved? In this way, there is no invariant problem, please ignore previous message. Thanks, bin