Hi, This patch adds the transforms mentioned in $subject. Bootstrap+test in progress on x86_64-unknown-linux-gnu. OK to commit if passes ?
Thanks, Prathamesh
2017-09-15 Prathamesh Kulkarni <prathamesh.kulka...@linaro.org> * match.pd ((X / Y) == 0 -> X < Y): New pattern. ((X / Y) != 0 -> X >= Y): Likewise. testsuite/ * gcc.dg/tree-ssa/cmpdiv.c: New test. diff --git a/gcc/match.pd b/gcc/match.pd index dbfceaf10a5..0e1b59c9c10 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1266,6 +1266,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))) (op @1 @0)))) +/* (X / Y) == 0 -> X < Y if X, Y are unsigned. */ +(simplify + (eq (trunc_div @0 @1) integer_zerop) + (if (TYPE_UNSIGNED (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE (@1))) + (lt @0 @1))) + +/* (X / Y) != 0 -> X >= Y, if X, Y are unsigned. */ +(simplify + (ne (trunc_div @0 @1) integer_zerop) + (if (TYPE_UNSIGNED (TREE_TYPE(@0)) && TYPE_UNSIGNED (TREE_TYPE (@1))) + (ge @0 @1))) + /* X == C - X can never be true if C is odd. */ (for cmp (eq ne) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c new file mode 100644 index 00000000000..14161f5ea6f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ + +_Bool f1(unsigned x, unsigned y) +{ + unsigned t1 = x / y; + _Bool t2 = (t1 != 0); + return t2; +} + +_Bool f2(unsigned x, unsigned y) +{ + unsigned t1 = x / y; + _Bool t2 = (t1 == 0); + return t2; +} + +/* { dg-final { scan-tree-dump-not "trunc_div_expr" "optimized" } } */