public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Optimize certain end of loop conditions into min/max operation
@ 2015-07-27  4:23 Michael Collison
  2015-07-27  7:36 ` Bin.Cheng
  2015-07-27  9:47 ` Richard Biener
  0 siblings, 2 replies; 29+ messages in thread
From: Michael Collison @ 2015-07-27  4:23 UTC (permalink / raw)
  To: gcc Patches

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.collison@linaro.org>
                     Andrew Pinski <andrew.pinski@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)))))
-- 

-- 
Michael Collison
Linaro Toolchain Working Group
michael.collison@linaro.org

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2015-10-06  9:21 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27  4:23 [PATCH] Optimize certain end of loop conditions into min/max operation Michael Collison
2015-07-27  7:36 ` Bin.Cheng
2015-07-27  8:11   ` Bin.Cheng
2015-07-27  9:47 ` Richard Biener
2015-07-27 16:25   ` Jeff Law
2015-07-28  7:59     ` Richard Biener
2015-07-29 22:38       ` Michael Collison
2015-07-31 16:40       ` Jeff Law
2015-07-31 18:48         ` Michael Collison
2015-07-31 19:10           ` Jeff Law
2015-08-03  7:34             ` Richard Biener
2015-09-18  7:00             ` Michael Collison
2015-09-18  7:38               ` Marc Glisse
2015-09-18  7:41                 ` Marc Glisse
2015-09-18 10:06                   ` Richard Biener
2015-09-30  8:08                     ` Michael Collison
2015-09-30  9:10                       ` Richard Biener
2015-09-30 16:51                         ` Michael Collison
2015-09-30 21:12                           ` Marc Glisse
2015-10-01  5:40                             ` Michael Collison
2015-10-01  6:42                               ` Marc Glisse
2015-10-01  7:59                             ` Michael Collison
2015-10-01  8:05                               ` Marc Glisse
2015-10-01  8:21                                 ` Michael Collison
2015-10-06  9:21                                   ` Richard Biener
2015-09-18 22:01                 ` Michael Collison
2015-09-18 22:09                   ` Marc Glisse
2015-08-05 16:08   ` Alan Lawrence
2015-08-05 16:15     ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).