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

--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Alexander Monakov from comment #0)
> I've tried to add the corresponding transform to match.pd, but it seems
> something else needs to be wired up as well, because it doesn't trigger.
> What am I missing? TIA.

What do the dumps look like? Gcc is likely to change things to -1 / B < A,
which you don't handle...

> +/* Simplify unsigned multiplication overflow check A > -1 / B to a builtin.
> */
> +(for cmp (gt le)
> +     out (ne eq)
> + (simplify
> +  (cmp @0 (trunc_div:s integer_all_onesp @1))
> +  (if (TYPE_UNSIGNED (TREE_TYPE (@0))
> +       && types_match (TREE_TYPE (@0), TREE_TYPE (@1)))

types_match seems unnecessary here, it is mostly useful when we have some
CONVERT_EXPR, but trunc's arguments and result types have to match, same for
cmp arguments, so @0 and @1 should always have matching types.

> +   (out
> +    (imagpart (IFN_MUL_OVERFLOW @0 @1))
> +    { build_zero_cst (TREE_TYPE (@0)); }))))

We probably need to disable such a transformation for vectors.

Reply via email to