Re: [PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Jakub Jelinek
On Mon, Feb 26, 2024 at 03:15:02PM +0100, Richard Biener wrote: > When folding a multiply CHRECs are handled like {a, +, b} * c > is {a*c, +, b*c} but that isn't generally correct when overflow > invokes undefined behavior. The following uses unsigned arithmetic > unless either a is zero or a and

Re: [PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Jakub Jelinek
On Mon, Feb 26, 2024 at 04:51:08PM +0100, Michael Matz wrote: > On Mon, 26 Feb 2024, Jakub Jelinek wrote: > > > > Will update the patch, I think any improvement should be done > > > to get_range_pos_neg (it's a bit odd in behavior for unsigned > > > but I have only signed things incoming). > > >

Re: [PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Michael Matz
Hello, On Mon, 26 Feb 2024, Jakub Jelinek wrote: > > Will update the patch, I think any improvement should be done > > to get_range_pos_neg (it's a bit odd in behavior for unsigned > > but I have only signed things incoming). > > For unsigned if it always returned 1, it would be quite useless,

Re: [PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Jakub Jelinek
On Mon, Feb 26, 2024 at 03:29:30PM +0100, Richard Biener wrote: > On Mon, 26 Feb 2024, Jakub Jelinek wrote: > > > On Mon, Feb 26, 2024 at 03:15:02PM +0100, Richard Biener wrote: > > > When folding a multiply CHRECs are handled like {a, +, b} * c > > > is {a*c, +, b*c} but that isn't generally

Re: [PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Richard Biener
On Mon, 26 Feb 2024, Jakub Jelinek wrote: > On Mon, Feb 26, 2024 at 03:15:02PM +0100, Richard Biener wrote: > > When folding a multiply CHRECs are handled like {a, +, b} * c > > is {a*c, +, b*c} but that isn't generally correct when overflow > > invokes undefined behavior. The following uses

Re: [PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Jakub Jelinek
On Mon, Feb 26, 2024 at 03:15:02PM +0100, Richard Biener wrote: > When folding a multiply CHRECs are handled like {a, +, b} * c > is {a*c, +, b*c} but that isn't generally correct when overflow > invokes undefined behavior. The following uses unsigned arithmetic > unless either a is zero or a and

[PATCH] tree-optimization/114074 - CHREC multiplication and undefined overflow

2024-02-26 Thread Richard Biener
When folding a multiply CHRECs are handled like {a, +, b} * c is {a*c, +, b*c} but that isn't generally correct when overflow invokes undefined behavior. The following uses unsigned arithmetic unless either a is zero or a and b have the same sign. I've used simple early outs for INTEGER_CSTs and