Simplify X /[ex] 8 == 0

Richard Biener richard.guenther@gmail.com
Fri Nov 4 13:15:00 GMT 2016


On Fri, Nov 4, 2016 at 1:34 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> Hello,
>
> this kind of simplification is already handled by fold_comparison, but the
> code is common with TRUNC_DIV_EXPR, which yields suboptimal code. In
> particular, for an unsigned number, X/8==0 means x<=7, while X/[ex]8==0 can
> be turned into X==0.
>
> When we have an explicit division by 0, there is a better optimisation
> possible (insert __builtin_unreachable() or __builtin_trap() after that
> statement, as in find_explicit_erroneous_behavior), so I don't touch it.
>
> For the overflow inequality case, it would have been a bit clearer to
> generate
>   (cmp { build_zero_cst (TREE_TYPE (@0)); } @2)
> and let that be constant folded instead of having that ugly and error-prone
> test in constant_boolean_node, but I saved one tree ;-)
>
> Bootstrap+regtest on powerpc64le-unknown-linux-gnu, all the regressions are
> in the libitm part of the testsuite, they should be fixed by
> https://gcc.gnu.org/ml/gcc-patches/2016-10/msg02220.html , I'll rerun the
> testsuite when that patch is in.

Ok.

You fail to handle A /[ex] -2 < 2?  Is that on purpose?  Or just lazy so you
dont' have to handle inverting the comparison?

Thanks,
Richard.

> 2016-11-07  Marc Glisse  <marc.glisse@inria.fr>
>
> gcc/
>         * fold-const.c (fold_comparison): Ignore EXACT_DIV_EXPR.
>         * match.pd (A /[ex] B CMP C): New simplifications.
>
> gcc/testsuite/
>         * gcc.dg/tree-ssa/cmpexactdiv.c: New file.
>
> --
> Marc Glisse



More information about the Gcc-patches mailing list