aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorEikansh Gupta <quic_eikagupt@quicinc.com>2024-11-11 17:25:45 +0530
committerAndrew Pinski <quic_apinski@quicinc.com>2024-11-16 11:10:49 -0800
commit5eadc673366c68a62264c55a570cbdfca96bbbaa (patch)
treefac8f699c2433fba894918ab52226a758f06da35 /gcc/testsuite
parent94bea5dd6c9a06ddb6244be1e5196ff5fbe2b186 (diff)
downloadgcc-5eadc673366c68a62264c55a570cbdfca96bbbaa.zip
gcc-5eadc673366c68a62264c55a570cbdfca96bbbaa.tar.gz
gcc-5eadc673366c68a62264c55a570cbdfca96bbbaa.tar.bz2
MATCH: Simplify `min(a, b) op max(a, b)` to `a op b` [PR109401]
This patch simplify `min(a,b) op max(a,b)` to `a op b`. This optimization will work for all the binary commutative operations. So, the `op` here can be one of {plus, mult, bit_and, bit_xor, bit_ior, eq, ne, min, max}. PR tree-optimization/109401 gcc/ChangeLog: * match.pd (min(a,b) op max(a,b) -> a op b): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr109401.c: New test. * gcc.dg/tree-ssa/pr109401-1.c: New test. Signed-off-by: Eikansh Gupta <quic_eikagupt@quicinc.com>
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr109401-1.c35
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr109401.c61
2 files changed, 96 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr109401-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr109401-1.c
new file mode 100644
index 0000000..3f72516
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr109401-1.c
@@ -0,0 +1,35 @@
+/* PR tree-optimization/109878 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+/* Returns max (a, b) */
+int max(int a, int b) {
+ if (b > a)
+ return b;
+ else
+ return a;
+}
+
+/* Returns min (a, b) */
+int min(int a, int b) {
+ if (b < a)
+ return b;
+ else
+ return a;
+}
+
+/* These functions should return a op b */
+int f8(int a, int b)
+{
+ return min (max (a, b), min (a, b));
+}
+
+int f9(int a, int b)
+{
+ return max (min (a, b), max (a, b));
+}
+
+/* Function min and f8 should have MIN_EXPR */
+/* Function max and f9 should have MAX_EXPR */
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR" 2 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr109401.c b/gcc/testsuite/gcc.dg/tree-ssa/pr109401.c
new file mode 100644
index 0000000..11177d9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr109401.c
@@ -0,0 +1,61 @@
+/* PR tree-optimization/109878 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+/* Returns max (a, b) */
+int max(int a, int b) {
+ if (b > a)
+ return b;
+ else
+ return a;
+}
+
+/* Returns min (a, b) */
+int min(int a, int b) {
+ if (b < a)
+ return b;
+ else
+ return a;
+}
+
+/* All the functions here shouldn't evalute min or max of a and b
+ * These functions should return a op b */
+int f(int a, int b)
+{
+ return max (a, b) + min (a, b);
+}
+
+int f1(int a, int b)
+{
+ return max (a, b) * min (a, b);
+}
+
+int f2(int a, int b)
+{
+ return max (a, b) | min (a, b);
+}
+
+int f3(int a, int b)
+{
+ return max (a, b) & min (a, b);
+}
+
+int f5(int a, int b)
+{
+ return min (a, b) ^ max (a, b);
+}
+
+int f6(int a, int b)
+{
+ return min (a, b) == max (a, b);
+}
+
+int f7(int a, int b)
+{
+ return min (a, b) != max (a, b);
+}
+
+/* Function min should have MIN_EXPR */
+/* Function max should have MAX_EXPR */
+/* { dg-final { scan-tree-dump-times "MIN_EXPR" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */