This series adds some more rules for identifying and folding exact divisions, including shifts right by C when the low C bits are known to be zero. It also extends some existing rules to handle poly_ints.
The original motivation was to improve address arithmetic for some upcoming SVE testcases. Bootstrapped & regression-tested on aarch64-linux-gnu. OK to install? Richard Richard Sandiford (9): Make more places handle exact_div like trunc_div Use get_nonzero_bits to simplify trunc_div to exact_div Simplify X /[ex] Y cmp Z -> X cmp (Y * Z) Simplify (X /[ex] C1) * (C1 * C2) -> X * C2 Generalise ((X /[ex] A) +- B) * A -> X +- A * B rule Try to simplify (X >> C1) << (C1 + C2) -> X << C2 Handle POLY_INT_CSTs in get_nonzero_bits Try to simplify (X >> C1) * (C2 << C1) -> X * C2 Record nonzero bits in the irange_bitmask of POLY_INT_CSTs gcc/match.pd | 164 +++++++++++++----- gcc/range-op-mixed.h | 9 +- gcc/range-op.cc | 19 +- gcc/range-op.h | 31 +++- gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-6.c | 29 ++++ gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-7.c | 21 +++ gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-8.c | 20 +++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-1.c | 23 +++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-2.c | 19 ++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-3.c | 21 +++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-4.c | 14 ++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-5.c | 29 ++++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-6.c | 59 +++++++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-7.c | 22 +++ gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-8.c | 20 +++ gcc/testsuite/gcc.dg/tree-ssa/shifts-1.c | 61 +++++++ gcc/testsuite/gcc.dg/tree-ssa/shifts-2.c | 21 +++ gcc/testsuite/gcc.dg/tree-ssa/shifts-3.c | 65 +++++++ gcc/testsuite/gcc.dg/tree-ssa/shifts-4.c | 23 +++ .../gcc.target/aarch64/sve/cnt_fold_1.c | 110 ++++++++++++ .../gcc.target/aarch64/sve/cnt_fold_2.c | 55 ++++++ .../gcc.target/aarch64/sve/cnt_fold_3.c | 40 +++++ .../gcc.target/aarch64/sve/cnt_fold_4.c | 61 +++++++ .../gcc.target/aarch64/sve/cnt_fold_5.c | 38 ++++ .../gcc.target/aarch64/sve/cnt_fold_6.c | 75 ++++++++ gcc/tree-ssa-loop-ivopts.cc | 2 + gcc/tree-ssa-loop-niter.cc | 2 +- gcc/tree-ssanames.cc | 3 + gcc/tree.h | 13 ++ gcc/value-query.cc | 7 + 30 files changed, 1018 insertions(+), 58 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-6.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-7.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-8.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-3.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-4.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-5.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-6.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-7.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/mulexactdiv-8.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/shifts-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/shifts-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/shifts-3.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/shifts-4.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_1.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_2.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_3.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_4.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_5.c create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cnt_fold_6.c -- 2.25.1