This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Simplify X /[ex] 8 == 0


On Fri, 4 Nov 2016, Richard Biener wrote:

On Fri, Nov 4, 2016 at 2:15 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
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?

Oh, I suppose nothing generates exact divisions by negative numbers.

Yes, that :-) I think I'd rather wait until I can test it before simplifying those too much.

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]