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: Jakub Jelinek <jakub at redhat dot com>
- To: Martin Liška <mliska at suse dot cz>
- Cc: gcc-patches at gcc dot gnu dot org, Alexander Monakov <amonakov at ispras dot ru>, Martin Jambor <mjambor at suse dot cz>
- Date: Mon, 22 Oct 2018 16:25:24 +0200
- 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>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Mon, Oct 22, 2018 at 04:08:53PM +0200, Martin Liška wrote:
> 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.
>
> Do you have any {over,under)flowing test-cases that I should add to test-suite?
I'm worried that the calculation you emit into the code could invoke UB at
runtime, even if there was no UB in the original code, and later GCC passes
would optimize with the assumption that UB doesn't occur.
E.g. if the multiplication overflows for one or more of the valid values in
the switch and then the addition adds a negative value so that the end
result is actually representable.
Jakub