On 07/31/2015 11:27 AM, Jeff Law wrote:
On 07/31/2015 12:18 PM, Michael Collison wrote:
Hi Jeff,
Yes I will create a test case. I'm not quite sure what to check for even
in the machine dependent test case. It's quite possible for the
instructions that are generated to change over time.
I think we're going to want to look at the gimple IR and search for
the MIN/MAX expressions rather than the instructions. Given we don't
know where the transformation is going to land (yet), you can probably
start with -fdump-tree-optimized and scanning the .optimized dump.
We can still do that and have the test be target specific.
jeff
Jeff and Richard,
Here is the the patch modified with test cases for MIN_EXPR and MAX_EXPR
expressions. I need some assistance; this test case will fail on targets
that don't have support for MIN/MAX such as 68k. Is there any way to
remedy this short of enumerating whether a target support MIN/MAX in
testsuite/lib/target_support?
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))
* testsuite/gcc.dg/tree-ssa/minmax-loopend.c: New test.
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)))))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c
b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c
new file mode 100644
index 0000000..cc0189a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#define N 1024
+
+int a[N], b[N], c[N];
+
+void add (unsigned int m, unsigned int n)
+{
+ unsigned int i;
+ for (i = 0; i < m && i < n; ++i)
+ a[i] = b[i] + c[i];
+}
+
+void add2 (unsigned int m, unsigned int n)
+{
+ unsigned int i;
+ for (i = N-1; i > m && i > n; --i)
+ a[i] = b[i] + c[i];
+}
+
+/* { dg-final { scan-tree-dump "MIN_EXPR" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump "MAX_EXPR" 1 "optimized" } } */
--
1.9.1
--
Michael Collison
Linaro Toolchain Working Group
michael.colli...@linaro.org