[PATCH] match.pd: Add abs with bitwise and pattern [PR106243]

2022-08-10 Thread Sam Feifer via Gcc-patches
This patch adds a simplification to match.pd that was discussed on the thread for pr106243. It simplifies the pattern, abs(x) & 1, to x & 1. There are also tests for the simplification in this patch. I couldn't figure out how to get abs to work with vectors. If a test for that is necessary, could

[PATCH] match.pd: Add bitwise and pattern [PR106243]

2022-08-03 Thread Sam Feifer via Gcc-patches
This patch adds a new optimization to match.pd. The pattern, -x & 1, now gets simplified to x & 1, reducing the number of instructions produced. This patch also adds tests for the optimization rule. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR tree-optimization/106243

Re: [PATCH] match.pd: Add new division pattern [PR104992]

2022-08-01 Thread Sam Feifer via Gcc-patches
Here is the patch that I pushed. Thanks for the feedback. Thanks -Sam On Thu, Jul 28, 2022 at 3:03 AM Richard Biener wrote: > On Wed, Jul 27, 2022 at 9:57 PM Sam Feifer wrote: > > > > > >> _Complex int are strange beasts, I'd simply avoid the transform for > them. > >> > > > > I added to the m

Re: [PATCH] match.pd: Add new division pattern [PR104992]

2022-07-27 Thread Sam Feifer via Gcc-patches
> _Complex int are strange beasts, I'd simply avoid the transform for them. > > I added to the match.pd rule to not simplify if the operands are complex. There is now a test case for complex types to make sure they do not simplify. I had to move the "dg-do run" test to g++.dg to accommodate the com

Re: [PATCH] match.pd: Add new division pattern [PR104992]

2022-07-26 Thread Sam Feifer via Gcc-patches
> > int f(_Complex int x, _Complex int y) > { > return x == x / y * y; > } > After some research about mod with complex types, I found that the binary mod operation does not work with complex types. If so, the complex test case should not be simplified. Is this correct? I should also note that

Re: [PATCH] match.pd: Add new division pattern [PR104992]

2022-07-25 Thread Sam Feifer via Gcc-patches
> I suspect for eq and mult you might want to add :c to them even though > in your testcase you don't need them, you might be able to get it via > using different statements and looking at the forwprop gimple dump. > Also, did you send the wrong patch as it looks like the function call > to build_z

[PATCH] match.pd: Add new division pattern [PR104992]

2022-07-25 Thread Sam Feifer via Gcc-patches
This patch fixes a missed optimization in match.pd. It takes the pattern, x / y * y == x, and optimizes it to x % y == 0. This produces fewer instructions. There are also tests for the optimizations to be added to the test suite. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

[pushed] match.pd: Add new abs pattern [PR94920]

2022-07-21 Thread Sam Feifer via Gcc-patches
This patch is intended to fix a missed optimization in match.pd. It optimizes (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) to just abs(x). Additionally, the pattern (x <= 0 ? -x : 0) now gets optimized to max(-x, 0), which helps with the other simplification rule. Tests are also included to be added to

[pushed] MAINTAINERS: Add myself to Write After Approval

2022-07-21 Thread Sam Feifer via Gcc-patches
ChangeLog: * MAINTAINERS (Write After Approval): Add myself. --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index e2db0cfe18b..46c9e48a497 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -398,6 +398,7 @@ Chris Fairles

Re: [PATCH] match.pd: Add new abs pattern [PR94290]

2022-07-19 Thread Sam Feifer via Gcc-patches
Attached is a patch file with those changes. Thanks -Sam On Tue, Jul 19, 2022 at 2:36 AM Richard Biener wrote: > On Mon, Jul 18, 2022 at 7:31 PM Sam Feifer via Gcc-patches > wrote: > > > > Just realized I had mixed up the 9 and the 2 when labelling the patch. > This >

Re: [PATCH] match.pd: Add new abs pattern [PR94290]

2022-07-18 Thread Sam Feifer via Gcc-patches
u, Jul 14, 2022 at 7:09 AM Sam Feifer wrote: >> >> > >> >> > >> >> > On Wed, Jul 13, 2022 at 3:36 PM Andrew Pinski >> wrote: >> >> >> >> >> >> On Wed, Jul 13, 2022 at 12:26 PM Sam Feifer via Gcc-patches >>

Re: [PATCH] match.pd: Add new abs pattern [PR94290]

2022-07-18 Thread Sam Feifer via Gcc-patches
On Thu, Jul 14, 2022 at 7:09 AM Sam Feifer wrote: > >> > > >> > > >> > On Wed, Jul 13, 2022 at 3:36 PM Andrew Pinski > wrote: > >> >> > >> >> On Wed, Jul 13, 2022 at 12:26 PM Sam Feifer via Gcc-patches > >> >> wrote: &

Re: [PATCH] match.pd: Add new abs pattern [PR94290]

2022-07-14 Thread Sam Feifer via Gcc-patches
On Thu, Jul 14, 2022 at 1:24 PM Andrew Pinski wrote: > On Thu, Jul 14, 2022 at 7:09 AM Sam Feifer wrote: > > > > > > On Wed, Jul 13, 2022 at 3:36 PM Andrew Pinski wrote: > >> > >> On Wed, Jul 13, 2022 at 12:26 PM Sam Feifer via Gcc-patches > >>

Re: [PATCH] match.pd: Add new abs pattern [PR94290]

2022-07-14 Thread Sam Feifer via Gcc-patches
On Wed, Jul 13, 2022 at 3:36 PM Andrew Pinski wrote: > On Wed, Jul 13, 2022 at 12:26 PM Sam Feifer via Gcc-patches > wrote: > > > > This patch is intended to fix a missed optimization in match.pd. It > optimizes (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) to just abs(x)

[PATCH] match.pd: Add new abs pattern [PR94290]

2022-07-13 Thread Sam Feifer via Gcc-patches
This patch is intended to fix a missed optimization in match.pd. It optimizes (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) to just abs(x). I had to write a second simplification in match.pd to handle the commutative property as the match was not ocurring otherwise. Additionally, the pattern (x <= 0 ? -x

[PATCH] match.pd: Add new bitwise arithmetic pattern [PR98304]

2022-07-07 Thread Sam Feifer via Gcc-patches
Hi! This patch is meant to solve a missed optimization in match.pd. It optimizes the following expression: n - (((n > 63) ? n : 63) & -64) where the constant being negated (in this case -64) is a power of 2 and the sum of the two constants is -1. For the signed case, this gets optimized to (n <