diff options
-rw-r--r-- | gcc/match.pd | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c | 12 |
5 files changed, 65 insertions, 3 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index d160156..56ac743 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2076,10 +2076,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (m1 CMP m2) * d -> (m1 CMP m2) ? d : 0 */ (if (!canonicalize_math_p ()) - (for cmp (gt lt ge le) + (for cmp (tcc_comparison) (simplify - (mult (convert (cmp @0 @1)) @2) - (cond (cmp @0 @1) @2 { build_zero_cst (type); })))) + (mult:c (convert (cmp@0 @1 @2)) @3) + (if (INTEGRAL_TYPE_P (type) + && INTEGRAL_TYPE_P (TREE_TYPE (@0))) + (cond @0 @3 { build_zero_cst (type); }))) +/* (-(m1 CMP m2)) & d -> (m1 CMP m2) ? d : 0 */ + (simplify + (bit_and:c (negate (convert (cmp@0 @1 @2))) @3) + (if (INTEGRAL_TYPE_P (type) + && INTEGRAL_TYPE_P (TREE_TYPE (@0))) + (cond @0 @3 { build_zero_cst (type); }))) + ) +) /* For integral types with undefined overflow and C != 0 fold x * C EQ/NE y * C into x EQ/NE y. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c new file mode 100644 index 0000000..6f16783 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-1.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/92342 */ + +int +f (int m1, int m2, int c) +{ + int d = m1 == m2; + d = -d; + int e = d & c; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c new file mode 100644 index 0000000..0e25c8a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/andnegcmp-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/92342 */ + +int +f (int m1, int m2, int c) +{ + int d = m1 < m2; + d = -d; + int e = c & d; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c new file mode 100644 index 0000000..fb44cac --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (int m1, int m2, int c) +{ + int d = m1 == m2; + int e = d * c; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c new file mode 100644 index 0000000..be38b2e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/multcmp-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (int m1, int m2, int c) +{ + int d = m1 != m2; + int e = c * d; + return e; +} + +/* { dg-final { scan-tree-dump-times "\\? c_\[0-9\]\\(D\\) : 0" 1 "optimized" } } */ |