This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Switch conversion: support any ax + b transformation (PR tree-optimization/84436).
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: Martin Liška <mliska at suse dot cz>
- Cc: Jakub Jelinek <jakub at redhat dot com>, gcc-patches at gcc dot gnu dot org, Martin Jambor <mjambor at suse dot cz>
- Date: Mon, 22 Oct 2018 17:17:44 +0300 (MSK)
- Subject: Re: [PATCH] Switch conversion: support any ax + b transformation (PR tree-optimization/84436).
- References: <c1f21703-b516-b7f2-b128-84dd7a939c50@suse.cz> <20181011130357.GA11625@tucnak> <888225f0-3b38-ddff-5d0f-9ff57cb0612d@suse.cz>
On Mon, 22 Oct 2018, Martin Liška wrote:
> On 10/11/18 3:03 PM, Jakub Jelinek wrote:
> > On Thu, Oct 11, 2018 at 02:56:14PM +0200, Martin Liška wrote:
> >> As seen in the PR, switch conversion can do better when we return equal numbers
> >> based on index value. I implemented more than that, more precisely I support all linear
> >> transformation based on index value. It's the same what clang is capable of.
> >
> > Not a review, just a question, do you check for overflows while computing
> > it? Or force the arithmetics to be performed in a type with defined
> > overflow. It would be bad to introduced UB...
>
> Very valid question. I hope as long as I calculate the linear function
> values in wide_int (get via wi::to_wide (switch_element)), then it should
> overflow in the same way as original tree type arithmetic. I have a test-case with
> overflow: gcc/testsuite/gcc.dg/tree-ssa/pr84436-4.c.
Sorry I missed this the first time around. Note the testcase should use 'signed
char', otherwise it depends on whether plain 'char' is signed or not.
I think this is the kind of invalid transformation Jakub was concerned about,
the transformation introduces signed multiplication that overflows and assumes
it would wrap around.
Alexander