On 10/22/18 4:17 PM, Alexander Monakov wrote:
> 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.

Good observation, I'll fix that.

> 
> 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.

About this, using TYPE_OVERFLOW_WRAPS (which relies on flag_wrapv) should be 
enough?

Martin

> 
> Alexander
> 

Reply via email to