]> gcc.gnu.org Git - gcc.git/commitdiff
match.pd: Improve y == MIN || x < y optimization [PR105983]
authorJakub Jelinek <jakub@redhat.com>
Thu, 16 Jun 2022 12:37:06 +0000 (14:37 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 16 Jun 2022 12:37:36 +0000 (14:37 +0200)
On the following testcase, we only optimize bar where this optimization
is performed at GENERIC folding time, but on GIMPLE it doesn't trigger
anymore, as we actually don't see
  (bit_and (ne @1 min_value) (ge @0 @1))
but
  (bit_and (ne @1 min_value) (le @1 @0))
genmatch handles :c modifier not just on commutative operations, but
also comparisons and in that case it means it swaps the comparison.

2022-06-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/105983
* match.pd (y == XXX_MIN || x < y -> x <= y - 1,
y != XXX_MIN && x >= y -> x > y - 1): Use :cs instead of :s
on non-equality comparisons.

* gcc.dg/tree-ssa/pr105983.c: New test.

gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr105983.c [new file with mode: 0644]

index ae5dc820fa5d9ff9ea2a9b1a6c05d60070a47212..3e9572e4c9cbc276a374cffc9747a019ff824e0b 100644 (file)
@@ -2460,14 +2460,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* y == XXX_MIN || x < y --> x <= y - 1 */
 (simplify
- (bit_ior:c (eq:s @1 min_value) (lt:s @0 @1))
+ (bit_ior:c (eq:s @1 min_value) (lt:cs @0 @1))
   (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
        && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
   (le @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))
 
 /* y != XXX_MIN && x >= y --> x > y - 1 */
 (simplify
- (bit_and:c (ne:s @1 min_value) (ge:s @0 @1))
+ (bit_and:c (ne:s @1 min_value) (ge:cs @0 @1))
   (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
        && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1)))
   (gt @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr105983.c b/gcc/testsuite/gcc.dg/tree-ssa/pr105983.c
new file mode 100644 (file)
index 0000000..46418c2
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR tree-optimization/105983 */
+/* { dg-do compile } */
+/* { dg-options "-O2 --param=logical-op-non-short-circuit=1 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-not " != 0;" "optimized" } } */
+/* { dg-final { scan-tree-dump-not " & " "optimized" } } */
+
+int
+foo (unsigned a, unsigned b)
+{
+  return b != 0 && a >= b;
+}
+
+int
+bar (unsigned a, unsigned b)
+{
+  return b != 0 & a >= b;
+}
This page took 0.094245 seconds and 5 git commands to generate.