https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127814

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
So looking myself when we apply versioning we are doing the cost check before
checking the assumptions and glob everything into a single BB:

_2439 = (unsigned int) cb_838;
_2438 = _4 + -1993837876;
_2437 = _2438 * -520093677;
_2436 = (unsigned int) _2437;
_2435 = _2439 - _2436;
_2434 = _2435 + 1040187353;
_2433 = _2434 > 1040187353;  <- cost check
_2432 = _4 + -1993837876;
_2431 = _2432 * -520093677;
_2430 = _2431 >= -1107296295;
_2429 = _4 + -1993837876;
_2428 = _2429 * -520093677;
_2427 = _2428 + -1040187353;
_2426 = cb_838 >= _2427;
_2425 = _2426 & _2430;  <- assumption
_2424 = _2425;
_2423 = _2424 & _2433;

we then split off the cost check but not the assumption.  There are many more
tests (version for alias checks, etc.) that could be similarly affected.

We still have to avoid the may_be_zero combination with the assumptions,
neither the assumptions nor the may_be_zero check are using unsigned
arithmetic.

I'll note the existing combination of may_be_zero with niter suffers from
a similar issue.  It does

                niter = fold_build3 (COND_EXPR, TREE_TYPE (niter), may_be_zero,
                                     build_int_cst (TREE_TYPE (niter), 0),
                                     rewrite_to_non_trapping_overflow (niter));

so caring for -ftrapv but not UB.  I think all of the callers of that
function want to avoid UB, so we should mutate that function to the GENERIC
variant of rewrite_to_defined_unconditional.  We might want to think
of even adjusting the gimplifier to handle COND_EXPR / TRUTH_{AND,OR}IF_EXPR
gimplification by rewriting to defined.

Reply via email to