[PATCH] match.pd: optimize unsigned mul overflow check
Marc Glisse
marc.glisse@inria.fr
Sun May 29 22:09:00 GMT 2016
On Sat, 28 May 2016, Alexander Monakov wrote:
> For unsigned A, B, 'A > -1 / B' is a nice predicate for checking whether 'A*B'
> overflows (or 'B && A > -1 / B' if B may be zero). Let's optimize it to an
> invocation of __builtin_mul_overflow to avoid the divide operation.
Hmm, that division by zero thing is a good point. I may be confusing with
dereferencing a null pointer, but I believe that some languages catch the
corresponding signal, so by removing that division you would be changing
the behavior. I wish we had a -fno-divisions-by-zero or equivalent, but
otherwise this may require an extra check like tree_expr_nonzero_p,
although we are quite inconsistent about this (we don't simplify x/x to 1,
but we do simplify 0%x to 0 if x is not (yet) known to be the constant 0).
We'll see what the reviewers think...
Any plan on optimizing the 'B && ovf' form?
--
Marc Glisse
More information about the Gcc-patches
mailing list