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: Richard Biener <richard dot guenther at gmail dot com>
- To: Robin Dapp <rdapp at linux dot vnet dot ibm dot com>
- Cc: "Bin.Cheng" <amker dot cheng at gmail dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 3 Jul 2017 15:10:02 +0200
- Subject: Re: [PATCH 2/3] Simplify wrapped binops
- Authentication-results: sourceware.org; auth=none
- References: <5790A709.4060804@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> <CAHFci2-zFEjPa4TokPca8EDF4zM5PU+0B8maFKa189=Pyrcj7Q@mail.gmail.com> <57eda9e0-8fbb-7508-f41e-d98000314012@linux.vnet.ibm.com> <CAHFci2-VJu5SbWzm43uozxRq2L=4Sxp0L573y-vPeK69RX_iaA@mail.gmail.com> <bb91b7d9-2d8d-72af-1741-bb5d97e64466@linux.vnet.ibm.com> <CAHFci2_GZb1k9DSrX1MR2ZUSLFQRxxAhRr4ywkfv0_PUrzn0VQ@mail.gmail.com> <3bb74016-ea97-53ba-348e-51113418e37c@linux.vnet.ibm.com> <CAFiYyc3HTUTAt9ETYqW9LB3i82XzYmN33jXCtWNXq8U0tF1biQ@mail.gmail.com> <3d769452-cd24-1f7b-6fb2-b556a51be55b@linux.vnet.ibm.com> <CAFiYyc0mkd=OQzJycfA42BWqkdb1XA8iBRS1KOSCUXbKkn=DTg@mail.gmail.com> <0a2a7c03-e47a-fabd-e535-30e19a64b563@linux.vnet.ibm.com>
On Wed, Jun 28, 2017 at 4:34 PM, Robin Dapp <rdapp@linux.vnet.ibm.com> wrote
>> ideally you'd use a wide-int here and defer the tree allocation to the result
>
> Did that in the attached version.
>
>> So I guess we never run into the outer_op == minus case as the above is
>> clearly wrong for that?
>
> Right, damn, not only was the treatment for this missing but it was
> bogus in the other pattern as well. Since we are mostly dealing with
> PLUS_EXPR anyways it's probably better to defer the MINUS_EXPR case for
> now. This will also slim down the patterns a bit.
>
>> try to keep vertical spacing in patterns minimal -- I belive that patterns
>> should be small enough to fit in a terminal window (24 lines).
>
> I find using the expanded wrapped_range condition in the simplification
> somewhat cumbersome, especially because I need the condition to evaluate
> to true by default making the initialization unintuitive. Yet, I guess
> setting wrapped_range = true was not terribly intuitive either...
+ /* Perform binary operation inside the cast if the constant fits
+ and (A + CST)'s range does not wrap. */
+ (with
+ {
+ bool min_ovf = true, max_ovf = false;
While the initialization value doesn't matter (wi::add will overwrite it)
better initialize both to false ;) Ah, you mean because we want to
transform only if get_range_info returned VR_RANGE. Indeed somewhat
unintuitive (but still the best variant for now).
+ wide_int w1 = @1;
+ w1 = w1.from (w1, TYPE_PRECISION (inner_type), TYPE_SIGN
+ (inner_type));
I think wi::from (@1, ....) should work as well.
+ (if (!((min_ovf && !max_ovf) || (!min_ovf && max_ovf)) )
+ (convert (plus @0 { {wide_int_to_tree (TREE_TYPE (@0), w1)}; })))
so I'm still missing a comment on why min_ovf && max_ovf is ok.
The simple-minded would have written
(if (! min_ovf && ! max_ovf)
...
I'd like to see testcase(s) with this patch, preferably exactly also for the
case of min_ovf && max_ovf. That said, consider (long)[0xfffffffe,
0xffffffff] + 2
which should have min_ovf and max_ovf which results in [0x0, 0x1] in type
unsigned int but [0x100000000, 0x100000001] in type long.
Richard.
> Regards
> Robin