Re: [PATCH] Fold (X<

2021-07-26 Thread Marc Glisse
On Mon, 26 Jul 2021, Roger Sayle wrote: The one aspect that's a little odd is that each transform is paired with a convert@1 variant, using the efficient match machinery to expose any zero extension to fold-const.c's tree_nonzero_bits functionality. Copying the first transform for context +(

[PATCH] Fold (X<

2021-07-26 Thread Roger Sayle
The easiest way to motivate these additions to match.pd is with the following example: unsigned int foo(unsigned char i) { return i | (i<<8) | (i<<16) | (i<<24); } which mainline with -O2 on x86_64 currently generates: foo:movzbl %dil, %edi movl%edi, %eax movl%edi,

Re: [PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2

2020-10-16 Thread Richard Biener
On Thu, 15 Oct 2020, guojiufu wrote: > Hi, > > I just had a check on below patch for PR66552. > https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html > It seems this patch works fine now. This patch fixes PR66552 which > request to optimizes (x shift (n mod C)) to > (x shift (n bit_

Re: [PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2

2020-10-15 Thread Segher Boessenkool
Hi! On Thu, Oct 15, 2020 at 03:52:01PM +0800, guojiufu wrote: > I just had a check on below patch for PR66552. > https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html > It seems this patch works fine now. This patch fixes PR66552 which > request to optimizes (x shift (n mod C)) to >

[PATCH] fold x << (n % C) to x << (n & C-1) if C meets power2

2020-10-15 Thread guojiufu via Gcc-patches
Hi, I just had a check on below patch for PR66552. https://gcc.gnu.org/pipermail/gcc-patches/2020-February/540930.html It seems this patch works fine now. This patch fixes PR66552 which request to optimizes (x shift (n mod C)) to (x shift (n bit_and (C - 1))) when C is a constant and power of two.

Re: [PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Richard Biener
On Tue, 7 May 2019, Jakub Jelinek wrote: > On Tue, May 07, 2019 at 01:50:23PM +0200, Marc Glisse wrote: > > > And actually it seems that we could optimize the plus1 == plus2 cases > > > even if HONOR_SIGN_DEPENDENT_ROUNDING (type), because even in fesetenv > > > (FE_DOWNWARD) mode the testcase pri

Re: [PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Jakub Jelinek
On Tue, May 07, 2019 at 01:50:23PM +0200, Marc Glisse wrote: > > And actually it seems that we could optimize the plus1 == plus2 cases > > even if HONOR_SIGN_DEPENDENT_ROUNDING (type), because even in fesetenv > > (FE_DOWNWARD) mode the testcase prints the first two (in all other modes all > > 4).

Re: [PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Marc Glisse
On Tue, 7 May 2019, Jakub Jelinek wrote: On Tue, May 07, 2019 at 09:55:21AM +0200, Jakub Jelinek wrote: On Tue, May 07, 2019 at 09:48:13AM +0200, Richard Biener wrote: Will leave the "correctness check" for other folks but the above is BTW, as I wanted to be sure about the correctness, I wro

Re: [PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Jakub Jelinek
On Tue, May 07, 2019 at 09:55:21AM +0200, Jakub Jelinek wrote: > On Tue, May 07, 2019 at 09:48:13AM +0200, Richard Biener wrote: > > Will leave the "correctness check" for other folks > > but the above is BTW, as I wanted to be sure about the correctness, I wrote a simple program (below). And actu

Re: [PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Jakub Jelinek
On Tue, May 07, 2019 at 09:48:13AM +0200, Richard Biener wrote: > Will leave the "correctness check" for other folks but the above is > better written as > > + (outer_op (inner_op @0 REAL_CST@1) REAL_CST@2) > +(if (real_zerop (@1) > + && real_zerop (@2) > > because that gets code-ge

Re: [PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Richard Biener
On Tue, 7 May 2019, Jakub Jelinek wrote: > Hi! > > fold_real_zero_addition_p will fold x + (-0.0) or x - 0.0 to x > when not -frounding-math, but not the rest of the options when > -fsigned-zeros, and not when -fsignaling-nans. > If we have (x + 0.0) + 0.0, we can fold that to just x + 0.0 even >

[PATCH] Fold (x + 0.0) + 0.0 to x + 0.0 (PR tree-optimization/90356)

2019-05-07 Thread Jakub Jelinek
Hi! fold_real_zero_addition_p will fold x + (-0.0) or x - 0.0 to x when not -frounding-math, but not the rest of the options when -fsigned-zeros, and not when -fsignaling-nans. If we have (x + 0.0) + 0.0, we can fold that to just x + 0.0 even when honoring signed zeros, and IMNSHO even when honori

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-10 Thread Richard Biener
On June 10, 2016 6:15:25 PM GMT+02:00, Jason Merrill wrote: >On Fri, Jun 10, 2016 at 3:11 AM, Richard Biener >wrote: >> On Thu, 9 Jun 2016, Jason Merrill wrote: >> >>> On Thu, Jun 9, 2016 at 3:39 AM, Richard Biener >wrote: >>> > On Thu, 9 Jun 2016, Jakub Jelinek wrote: >>> > >>> >> On Thu, Jun 0

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-10 Thread Jason Merrill
On Fri, Jun 10, 2016 at 3:11 AM, Richard Biener wrote: > On Thu, 9 Jun 2016, Jason Merrill wrote: > >> On Thu, Jun 9, 2016 at 3:39 AM, Richard Biener wrote: >> > On Thu, 9 Jun 2016, Jakub Jelinek wrote: >> > >> >> On Thu, Jun 09, 2016 at 08:50:15AM +0200, Richard Biener wrote: >> >> > On Wed, 8 J

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-10 Thread Richard Biener
On Thu, 9 Jun 2016, Jason Merrill wrote: > On Thu, Jun 9, 2016 at 3:39 AM, Richard Biener wrote: > > On Thu, 9 Jun 2016, Jakub Jelinek wrote: > > > >> On Thu, Jun 09, 2016 at 08:50:15AM +0200, Richard Biener wrote: > >> > On Wed, 8 Jun 2016, Jason Merrill wrote: > >> > > >> > > On Wed, Jun 8, 201

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-09 Thread Jason Merrill
On Thu, Jun 9, 2016 at 3:39 AM, Richard Biener wrote: > On Thu, 9 Jun 2016, Jakub Jelinek wrote: > >> On Thu, Jun 09, 2016 at 08:50:15AM +0200, Richard Biener wrote: >> > On Wed, 8 Jun 2016, Jason Merrill wrote: >> > >> > > On Wed, Jun 8, 2016 at 11:16 AM, Marc Glisse >> > > wrote: >> > > > On W

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-09 Thread Richard Biener
On Thu, 9 Jun 2016, Jakub Jelinek wrote: > On Thu, Jun 09, 2016 at 08:50:15AM +0200, Richard Biener wrote: > > On Wed, 8 Jun 2016, Jason Merrill wrote: > > > > > On Wed, Jun 8, 2016 at 11:16 AM, Marc Glisse wrote: > > > > On Wed, 8 Jun 2016, Richard Biener wrote: > > > > > > > >> The following w

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-09 Thread Jakub Jelinek
On Thu, Jun 09, 2016 at 08:50:15AM +0200, Richard Biener wrote: > On Wed, 8 Jun 2016, Jason Merrill wrote: > > > On Wed, Jun 8, 2016 at 11:16 AM, Marc Glisse wrote: > > > On Wed, 8 Jun 2016, Richard Biener wrote: > > > > > >> The following works around PR70992 but the issue came up repeatedly > >

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Richard Biener
On Thu, 9 Jun 2016, Marc Glisse wrote: > On Wed, 8 Jun 2016, Jakub Jelinek wrote: > > > On Wed, Jun 08, 2016 at 01:43:56PM -0400, Jason Merrill wrote: > > > > A few random ideas I was considering: > > > > * restrict it to GIMPLE, so we can't have a regression in the > > > > front-ends. > > > > *

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Richard Biener
On Wed, 8 Jun 2016, Jason Merrill wrote: > On Wed, Jun 8, 2016 at 11:16 AM, Marc Glisse wrote: > > On Wed, 8 Jun 2016, Richard Biener wrote: > > > >> The following works around PR70992 but the issue came up repeatedly > >> that we are not very consistent in preserving the undefined behavior > >>

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Marc Glisse
On Wed, 8 Jun 2016, Jakub Jelinek wrote: On Wed, Jun 08, 2016 at 01:43:56PM -0400, Jason Merrill wrote: A few random ideas I was considering: * restrict it to GIMPLE, so we can't have a regression in the front-ends. * fold x/0 to 0 with TREE_OVERFLOW set, to tell the front-end that something is

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Jakub Jelinek
On Wed, Jun 08, 2016 at 01:43:56PM -0400, Jason Merrill wrote: > > A few random ideas I was considering: > > * restrict it to GIMPLE, so we can't have a regression in the front-ends. > > * fold x/0 to 0 with TREE_OVERFLOW set, to tell the front-end that something > > is going on. > > * fold to (x/y

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Jason Merrill
On Wed, Jun 8, 2016 at 11:16 AM, Marc Glisse wrote: > On Wed, 8 Jun 2016, Richard Biener wrote: > >> The following works around PR70992 but the issue came up repeatedly >> that we are not very consistent in preserving the undefined behavior >> of division or modulo by zero. Ok - the only inconsis

Re: [PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Marc Glisse
On Wed, 8 Jun 2016, Richard Biener wrote: The following works around PR70992 but the issue came up repeatedly that we are not very consistent in preserving the undefined behavior of division or modulo by zero. Ok - the only inconsistency is that we fold 0 % x to 0 but not 0 % 0 (with literal ze

[PATCH] Fold x/x to 1, 0/x to 0 and 0%x to 0 consistently

2016-06-08 Thread Richard Biener
The following works around PR70992 but the issue came up repeatedly that we are not very consistent in preserving the undefined behavior of division or modulo by zero. Ok - the only inconsistency is that we fold 0 % x to 0 but not 0 % 0 (with literal zero). After folding is now no longer done ea

[PATCH] Fold (X * CST1) & CST2

2012-05-08 Thread Richard Guenther
This makes us fold (X * 8) & 5 to zero and (X * 6) & 5 to (X * 6) & 4. It amends the fix for PR52134 in that I noticed we fail to do some simplifications on size expressions (later on SSA, CCP does the above transform, though not (yet) changing of the constant). Bootstrap and regtest ongoing on x