This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Discard P - (P + CST) optimization in pointer_diff (PR c/61240)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: Jeff Law <law at redhat dot com>, Richard Biener <rguenther at suse dot de>, GCC Patches <gcc-patches at gcc dot gnu dot org>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Wed, 6 Aug 2014 10:26:29 +0200
- Subject: Re: [C PATCH] Discard P - (P + CST) optimization in pointer_diff (PR c/61240)
- Authentication-results: sourceware.org; auth=none
- References: <20140804101856 dot GB24292 at redhat dot com> <alpine dot LSU dot 2 dot 11 dot 1408041224210 dot 20733 at zhemvz dot fhfr dot qr> <20140804113836 dot GD24292 at redhat dot com> <alpine dot LSU dot 2 dot 11 dot 1408041404040 dot 20733 at zhemvz dot fhfr dot qr> <20140805143652 dot GG24292 at redhat dot com> <53E13B1D dot 5050401 at redhat dot com> <20140806082219 dot GI24292 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Aug 06, 2014 at 10:22:19AM +0200, Marek Polacek wrote:
> On Tue, Aug 05, 2014 at 02:14:21PM -0600, Jeff Law wrote:
> > My concern is the code we're removing discusses the need to simplify when
> > these expressions are in static initializers. What's going to ensure that
> > we're still simplifying instances which appear in static initializers? I
> > don't see anything which tests that. And does it still work for targets
> > which utilize PSImode?
>
> Aw nuts. So with the patch we'd start erroring out on
> static __PTRDIFF_TYPE__ d1 = p - (p + 1);
> static __PTRDIFF_TYPE__ d2 = p - (p - 1);
> (it's nowhere in the testsuite/code base - and I hadn't noticed that
> until today :()
> while we'd still accept
> static __PTRDIFF_TYPE__ d5 = (p - 1) - p;
> static __PTRDIFF_TYPE__ d6 = (p + 1) - p;
> (Those are not constant expression according to ISO C.)
>
> The reason is that fold_build can fold
> "(long int) (p + 4) - (long int) p" to 4, but not
> "(long int) p - (long int) (p + 4)".
>
> That means we have to have a way how to fold the latter, but only in
> static initializers. So I guess I need to implement this in
> fold-const.c... Oh well.
>
> Nevertheless, I'd guess the fwprop bits could go in separately (it's
> beneficial for C++).
Well, if you are going to implement it in fwprop AND fold-const, then the
natural place to fix that would be in *.pd on the match-and-simplify branch.
Jakub