Hi, This follow-up patch implements the patterns mentioned in $subject. Bootstrap+test in progress on x86_64-unknown-linux-gnu and aarch64-linux-gnu. OK to commit if passes ?
Thanks, Prathamesh
2017-10-03 Prathamesh Kulkarni <prathamesh.kulka...@linaro.org> * match.pd ((X >> CST) == 0 -> X < (1 << CST)): New pattern. ((X >> CST) != 0 -> X >= (1 << CST)): Likewise. testsuite/ * gcc.dg/tree-ssa/cmpdiv.c: Add test-cases f3 and f4. diff --git a/gcc/match.pd b/gcc/match.pd index 43ab226a705..883ad5ba53c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1287,6 +1287,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (VECTOR_TYPE_P (type) || !VECTOR_TYPE_P (TREE_TYPE (@0)))) (ocmp @0 @1)))) +/* Transform + (x >> cst) != 0 -> x >= (1 << cst) + (x >> cst) == 0 -> x < (1 << cst) + if x, cst are unsigned. */ +(for cmp (eq ne) + ocmp (lt ge) + (simplify + (cmp (rshift @0 INTEGER_CST@1) integer_zerop) + (if (TYPE_UNSIGNED (TREE_TYPE (@0)) + && (VECTOR_TYPE_P (type) || !VECTOR_TYPE_P (TREE_TYPE (@0)))) + (ocmp @0 (lshift { build_int_cstu (TREE_TYPE (@0), 1); } @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 index 14161f5ea6f..fc5bc8c3674 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c @@ -15,4 +15,19 @@ _Bool f2(unsigned x, unsigned y) return t2; } +_Bool f3(unsigned x) +{ + unsigned t1 = x >> 4; + _Bool t2 = (t1 != 0); + return t2; +} + +_Bool f4(unsigned x) +{ + unsigned t1 = x >> 4; + _Bool t2 = (t1 == 0); + return t2; +} + /* { dg-final { scan-tree-dump-not "trunc_div_expr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "rshift_expr" "optimized" } } */