On Thu, May 18, 2017 at 3:47 PM, Robin Dapp <[email protected]> wrote:
> match.pd part of the patch.
>
> gcc/ChangeLog:
>
> 2017-05-18 Robin Dapp <[email protected]>
>
> * match.pd: Simplify wrapped binary operations.
> * tree-vrp.c (extract_range_from_binary_expr_1): Add overflow
> parameter.
> (extract_range_from_binary_expr): Likewise.
> * tree-vrp.h: Export.
Hi,
I didn't follow this issue from the beginning, so might asking stupid questions.
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 80a17ba..3fa18b9 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -1290,6 +1290,85 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (if (cst && !TREE_OVERFLOW (cst))
> (plus { cst; } @0))))
>
> +/* ((T)(A +- CST)) +- CST -> (T)(A) +- CST) */
> +#if GIMPLE
> + (for outer_op (plus minus)
> + (for inner_op (plus minus)
> + (simplify
> + (outer_op (convert (inner_op@3 @0 INTEGER_CST@1)) INTEGER_CST@2)
> + (if (TREE_CODE (type) == INTEGER_TYPE
> + && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (@3)))
> + (with
> + {
> + bool ovf = true;
> +
> + tree cst = NULL_TREE;
> + tree inner_type = TREE_TYPE (@3);
> + value_range vr = VR_INITIALIZER;
> +
> + /* Convert combined constant to tree of outer type if
> + there was no overflow in the original operation. */
> + wide_int minv, maxv;
> + if (TYPE_OVERFLOW_UNDEFINED (inner_type)
> + || (extract_range_from_binary_expr (&vr, inner_op,
> + inner_type, @0, @1, &ovf), vr.type == VR_RANGE))
Any reason to expose tree-vrp.c internal interface here? The function
looks quite expensive. Overflow check can be done by get_range_info
and simple wi::cmp calls. Existing code like in
tree-ssa-loop-niters.c already does that. Also could you avoid using
comma expressions in condition please? It only makes the code harder
to be read.
Thanks,
bin