Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Jakub Jelinek via Gcc-patches
On Fri, Aug 07, 2020 at 11:36:59PM +0200, Marc Glisse wrote: > > > https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm is the most > > > common way to compute the modular multiplicative inverse of a number. For > > > 3 > > > and 2^32, it could tell us that 2863311531*3-2*2^32=1, so modulo 2

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Joern Wolfgang Rennecke
On 07/08/20 21:57, Marc Glisse wrote: On Fri, 7 Aug 2020, Joern Wolfgang Rennecke wrote: However, there are cases were the second division will not be possible without rest. Consider : 7*X == 3 3/7 is 0 rest 3. 0x1 / 7 is 0x24924924 rest 4 Since 3 cannot be represented as an integer

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Marc Glisse
On Fri, 7 Aug 2020, Jakub Jelinek wrote: On Fri, Aug 07, 2020 at 10:57:54PM +0200, Marc Glisse wrote: On Fri, 7 Aug 2020, Joern Wolfgang Rennecke wrote: On 07/08/20 19:21, Marc Glisse wrote: If we are going to handle the wrapping case, we shouldn't limit to the non-wrapping meaning of mult

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Jakub Jelinek via Gcc-patches
On Fri, Aug 07, 2020 at 10:57:54PM +0200, Marc Glisse wrote: > On Fri, 7 Aug 2020, Joern Wolfgang Rennecke wrote: > > > > > On 07/08/20 19:21, Marc Glisse wrote: > > > > > > If we are going to handle the wrapping case, we shouldn't limit to > > > the non-wrapping meaning of multiplicity. 3*X==5

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Marc Glisse
On Fri, 7 Aug 2020, Joern Wolfgang Rennecke wrote: On 07/08/20 19:21, Marc Glisse wrote: If we are going to handle the wrapping case, we shouldn't limit to the non-wrapping meaning of multiplicity. 3*X==5 should become X==1431655767 (for a 32 bit type), etc. Do we have an extended gcd som

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Joern Wolfgang Rennecke
On 07/08/20 19:21, Marc Glisse wrote: If we are going to handle the wrapping case, we shouldn't limit to the non-wrapping meaning of multiplicity. 3*X==5 should become X==1431655767 (for a 32 bit type), etc. Do we have an extended gcd somewhere in gcc, to help compute 1431655767? I don't

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Marc Glisse
On Fri, 7 Aug 2020, Joern Wolfgang Rennecke wrote: this transformation is quite straightforward, without overflow, 3*X==15 is the same as X==5 and 3*X==5 cannot happen. Actually, with binary and decimal computers, this transformation (with these specific numbers) is also valid for wrapping ov

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-07 Thread Joern Wolfgang Rennecke
this transformation is quite straightforward, without overflow, 3*X==15 is the same as X==5 and 3*X==5 cannot happen. Actually, with binary and decimal computers, this transformation (with these specific numbers) is also valid for wrapping overflow. More generally, it is valid for wrapping ov

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-04 Thread Marc Glisse
On Mon, 3 Aug 2020, Richard Biener wrote: On Sat, Aug 1, 2020 at 9:29 AM Marc Glisse wrote: Hello, this transformation is quite straightforward, without overflow, 3*X==15 is the same as X==5 and 3*X==5 cannot happen. Adding a single_use restriction for the first case didn't seem necessary, a

Re: Simplify X * C1 == C2 with undefined overflow

2020-08-03 Thread Richard Biener via Gcc-patches
On Sat, Aug 1, 2020 at 9:29 AM Marc Glisse wrote: > > Hello, > > this transformation is quite straightforward, without overflow, 3*X==15 is > the same as X==5 and 3*X==5 cannot happen. Adding a single_use restriction > for the first case didn't seem necessary, although of course it can > slightly

Simplify X * C1 == C2 with undefined overflow

2020-08-01 Thread Marc Glisse
Hello, this transformation is quite straightforward, without overflow, 3*X==15 is the same as X==5 and 3*X==5 cannot happen. Adding a single_use restriction for the first case didn't seem necessary, although of course it can slightly increase register pressure in some cases. Bootstrap+regtes