This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Switch conversion: support any ax + b transformation (PR tree-optimization/84436).


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]