This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 2/3] Simplify wrapped binops
- From: "Bin.Cheng" <amker dot cheng at gmail dot com>
- To: Robin Dapp <rdapp at linux dot vnet dot ibm dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 18 May 2017 16:36:10 +0100
- Subject: Re: [PATCH 2/3] Simplify wrapped binops
- Authentication-results: sourceware.org; auth=none
- References: <5790A709.4060804@linux.vnet.ibm.com> <fea2a49d-5f2a-ae24-8601-44e52a2d76b4@linux.vnet.ibm.com> <CAFiYyc2UKpz4krcaxow_=yF6_eFZU_=M5k+6VTHZscDz+g=2uw@mail.gmail.com> <6bc1abab-9b54-fb67-fe98-9aaf993859dd@linux.vnet.ibm.com> <CAFiYyc28DaMGuzcMPZQ+AmHXuuNDAyAorMbW0Vo02EEoyZ+xSg@mail.gmail.com> <aba5346a-027f-ee35-0406-3998ab484621@linux.vnet.ibm.com> <CAFiYyc0aExY-MmRczHKJuQ8UFOpMy_+dzV-n05UJJOhuZVywTg@mail.gmail.com> <CAFiYyc0gnMe7j+DgTeudnpH-zD22nK7Cuv4a2zj4Va-anApTBA@mail.gmail.com> <27be603c-4499-ca96-f252-40934d3e420d@linux.vnet.ibm.com> <CAFiYyc1s699beSC9bpDGxY_2ppenDLoP3nbjYSnThF1cp2YHDA@mail.gmail.com> <d6e24bfd-fc3e-4160-fe27-db3eda5b857c@linux.vnet.ibm.com> <CAFiYyc1AcFG8JzoO3LYW9iyGsPj+7Kv17weZp+U3vTaeiqdhKA@mail.gmail.com> <260c4925-29e2-d50a-871e-397e2f9f4efb@linux.vnet.ibm.com> <CAFiYyc2_WX+3vzX27iRO9byK4zoc8N43F-d=Cg2xXoHwLRTgGQ@mail.gmail.com> <CAHFci299r3v3jbaZn0pzKPmk+yvF=Hwnbq+hxYGJCz-y8Qx0jg@mail.gmail.com> <803f5629-2a68-db02-a3a1-16fbe656f242@linux.vnet.ibm.com>
On Thu, May 18, 2017 at 3:47 PM, Robin Dapp <rdapp@linux.vnet.ibm.com> wrote:
> match.pd part of the patch.
>
> gcc/ChangeLog:
>
> 2017-05-18 Robin Dapp <rdapp@linux.vnet.ibm.com>
>
> * 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