This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Wed, 8 Jun 2016 19:52:35 +0200
- Subject: Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot LSU dot 2 dot 11 dot 1606081235210 dot 1493 at t29 dot fhfr dot qr> <alpine dot DEB dot 2 dot 20 dot 1606081629080 dot 2129 at laptop-mg dot saclay dot inria dot fr> <CADzB+2nfhu30aLwxvZC-p364wqEUnVBUwK2PyxAFc5=TgnR2OA at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Jun 08, 2016 at 01:43:56PM -0400, Jason Merrill wrote:
> > A few random ideas I was considering:
> > * restrict it to GIMPLE, so we can't have a regression in the front-ends.
> > * fold x/0 to 0 with TREE_OVERFLOW set, to tell the front-end that something
> > is going on.
> > * fold to (x/y,0) or (x/y,1) so the division by 0 is still there, but C++11
> > constexpr might give a strange message about it, and folding might not be
> > idempotent.
>
> Any of these would avoid the constexpr regression, though the second
> would make the diagnostic worse. Or the front end could copy
> constexpr function bodies before folding.
Or, both cxx_eval_binary_expression and cp_fold would need to
not fold if the divisor is integer_zerop.
Jakub