* [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare @ 2021-01-04 20:50 Eugene Rozenfeld 2021-01-05 12:21 ` Richard Biener 0 siblings, 1 reply; 6+ messages in thread From: Eugene Rozenfeld @ 2021-01-04 20:50 UTC (permalink / raw) To: Richard Biener, gcc-patches [-- Attachment #1: Type: text/plain, Size: 2163 bytes --] Ping. -----Original Message----- From: Eugene Rozenfeld Sent: Tuesday, December 22, 2020 3:01 PM To: Richard Biener <richard.guenther@gmail.com>; gcc-patches@gcc.gnu.org Subject: RE: Optimize combination of comparisons to dec+compare Re-sending my question and re-attaching the patch. Richard, can you please clarify your feedback? Thanks, Eugene -----Original Message----- From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of Eugene Rozenfeld via Gcc-patches Sent: Tuesday, December 15, 2020 2:06 PM To: Richard Biener <richard.guenther@gmail.com> Cc: gcc-patches@gcc.gnu.org Subject: [EXTERNAL] Re: Optimize combination of comparisons to dec+compare Richard, > Do we already handle x < y || x <= CST to x <= y - CST? That is an invalid transformation: e.g., consider x=3, y=4, CST=2. Can you please clarify? Thanks, Eugene -----Original Message----- From: Richard Biener <richard.guenther@gmail.com> Sent: Thursday, December 10, 2020 12:21 AM To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> Cc: gcc-patches@gcc.gnu.org Subject: Re: Optimize combination of comparisons to dec+compare On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > This patch adds a pattern for optimizing x < y || x == XXX_MIN to x <= > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. Do we already handle x < y || x <= CST to x <= y - CST? That is, the XXX_MIN case is just a special-case of generic anti-range testing? For anti-range testing with signed types we pun to unsigned when possible. > This fixes pr96674. > > Tested on x86_64-pc-linux-gnu. > > For this function > > bool f(unsigned a, unsigned b) > { > return (b == 0) | (a < b); > } > > the code without the patch is > > test esi,esi > sete al > cmp esi,edi > seta dl > or eax,edx > ret > > the code with the patch is > > sub esi,0x1 > cmp esi,edi > setae al > ret > > Eugene > > gcc/ > PR tree-optimization/96674 > * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 > > gcc/testsuite > * gcc.dg/pr96674.c: New test. > [-- Attachment #2: 0001-Optimize-combination-of-comparisons-to-dec-compare.patch --] [-- Type: application/octet-stream, Size: 2504 bytes --] From 39215c58f5f640920d81cbe43503342c8b518cd9 Mon Sep 17 00:00:00 2001 From: Eugene Rozenfeld <erozen@microsoft.com> Date: Wed, 9 Dec 2020 16:44:25 -0800 Subject: [PATCH] Optimize combination of comparisons to dec+compare This patch adds a pattern for optimizing x < y || x == XXX_MIN to x <= y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. This fixes pr96674. Tested on x86_64-pc-linux-gnu. For this function bool f(unsigned a, unsigned b) { return (b == 0) | (a < b); } the code without the patch is test esi,esi sete al cmp esi,edi seta dl or eax,edx ret the code with the patch is sub esi,0x1 cmp esi,edi setae al ret gcc/ PR tree-optimization/96674 * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 gcc/testsuite * gcc.dg/pr96674.c: New test. --- gcc/match.pd | 7 +++++++ gcc/testsuite/gcc.dg/pr96674.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr96674.c diff --git a/gcc/match.pd b/gcc/match.pd index 68201ff2e07..c29af540152 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2084,6 +2084,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (eqne == NE_EXPR) { constant_boolean_node (true, type); })))) +/* x < y || x == XXX_MIN --> x <= y - 1 */ +(simplify + (bit_ior (eq @1 min_value) (lt @0 @1)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) + (le @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))) + /* Convert (X == CST1) && (X OP2 CST2) to a known value based on CST1 OP2 CST2. Similarly for (X != CST1). */ diff --git a/gcc/testsuite/gcc.dg/pr96674.c b/gcc/testsuite/gcc.dg/pr96674.c new file mode 100644 index 00000000000..c7f20bffabb --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96674.c @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-options "-O -fdump-tree-optimized -fwrapv" } */ + +#include <limits.h> +#include <stdbool.h> + +bool __attribute__ ((noinline)) test1 (unsigned a, unsigned b) +{ + return (b == 0) | (a < b); +} + +bool __attribute__ ((noinline)) test2 (int a, int b) +{ + return (b == INT_MIN) | (a < b); +} + +int main() +{ + if (!test1 (1, 0) || !test1 (1, 2) || test1 (2, 1) || + !test2 (1, INT_MIN) || !test2 (1, 2) || test2 (2, 1)) { + __builtin_abort(); + } + + return 0; +} + +/* { dg-final { scan-tree-dump-times "\\+ 4294967295;" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "\\+ -1;" 1 "optimized" } } */ -- 2.17.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare 2021-01-04 20:50 [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare Eugene Rozenfeld @ 2021-01-05 12:21 ` Richard Biener 2021-01-14 21:04 ` [EXTERNAL] " Eugene Rozenfeld 0 siblings, 1 reply; 6+ messages in thread From: Richard Biener @ 2021-01-05 12:21 UTC (permalink / raw) To: Eugene Rozenfeld; +Cc: gcc-patches On Mon, Jan 4, 2021 at 9:50 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > Ping. > > -----Original Message----- > From: Eugene Rozenfeld > Sent: Tuesday, December 22, 2020 3:01 PM > To: Richard Biener <richard.guenther@gmail.com>; gcc-patches@gcc.gnu.org > Subject: RE: Optimize combination of comparisons to dec+compare > > Re-sending my question and re-attaching the patch. > > Richard, can you please clarify your feedback? Hmm, OK. The patch is OK. Thanks, Richard. > Thanks, > > Eugene > > -----Original Message----- > From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of Eugene Rozenfeld via Gcc-patches > Sent: Tuesday, December 15, 2020 2:06 PM > To: Richard Biener <richard.guenther@gmail.com> > Cc: gcc-patches@gcc.gnu.org > Subject: [EXTERNAL] Re: Optimize combination of comparisons to dec+compare > > Richard, > > > Do we already handle x < y || x <= CST to x <= y - CST? > > That is an invalid transformation: e.g., consider x=3, y=4, CST=2. > Can you please clarify? > > Thanks, > > Eugene > > -----Original Message----- > From: Richard Biener <richard.guenther@gmail.com> > Sent: Thursday, December 10, 2020 12:21 AM > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > Cc: gcc-patches@gcc.gnu.org > Subject: Re: Optimize combination of comparisons to dec+compare > > On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > This patch adds a pattern for optimizing x < y || x == XXX_MIN to x <= > > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. > > Do we already handle x < y || x <= CST to x <= y - CST? > That is, the XXX_MIN case is just a special-case of generic anti-range testing? For anti-range testing with signed types we pun to unsigned when possible. > > > This fixes pr96674. > > > > Tested on x86_64-pc-linux-gnu. > > > > For this function > > > > bool f(unsigned a, unsigned b) > > { > > return (b == 0) | (a < b); > > } > > > > the code without the patch is > > > > test esi,esi > > sete al > > cmp esi,edi > > seta dl > > or eax,edx > > ret > > > > the code with the patch is > > > > sub esi,0x1 > > cmp esi,edi > > setae al > > ret > > > > Eugene > > > > gcc/ > > PR tree-optimization/96674 > > * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 > > > > gcc/testsuite > > * gcc.dg/pr96674.c: New test. > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare 2021-01-05 12:21 ` Richard Biener @ 2021-01-14 21:04 ` Eugene Rozenfeld 2021-01-15 11:54 ` Richard Biener 0 siblings, 1 reply; 6+ messages in thread From: Eugene Rozenfeld @ 2021-01-14 21:04 UTC (permalink / raw) To: Richard Biener, gabravier, jakub; +Cc: gcc-patches [-- Attachment #1: Type: text/plain, Size: 3371 bytes --] I got more feedback for the patch from Gabriel Ravier and Jakub Jelinek in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674 and re-worked it accordingly. The changes from the previous patch are: 1. Switched the tests to use __attribute__((noipa)) instead of __attribute__((noinline)) . 2. Fixed a type in the pattern comment. 3. Added :c for top-level bit_ior expression. 4. Added :s for the subexpressions. 5. Added a pattern for the negated expression: x >= y && y != XXX_MIN --> x > y - 1 and the corresponding tests. The new patch is attached. Eugene -----Original Message----- From: Richard Biener <richard.guenther@gmail.com> Sent: Tuesday, January 5, 2021 4:21 AM To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> Cc: gcc-patches@gcc.gnu.org Subject: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare On Mon, Jan 4, 2021 at 9:50 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > Ping. > > -----Original Message----- > From: Eugene Rozenfeld > Sent: Tuesday, December 22, 2020 3:01 PM > To: Richard Biener <richard.guenther@gmail.com>; > gcc-patches@gcc.gnu.org > Subject: RE: Optimize combination of comparisons to dec+compare > > Re-sending my question and re-attaching the patch. > > Richard, can you please clarify your feedback? Hmm, OK. The patch is OK. Thanks, Richard. > Thanks, > > Eugene > > -----Original Message----- > From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of > Eugene Rozenfeld via Gcc-patches > Sent: Tuesday, December 15, 2020 2:06 PM > To: Richard Biener <richard.guenther@gmail.com> > Cc: gcc-patches@gcc.gnu.org > Subject: [EXTERNAL] Re: Optimize combination of comparisons to > dec+compare > > Richard, > > > Do we already handle x < y || x <= CST to x <= y - CST? > > That is an invalid transformation: e.g., consider x=3, y=4, CST=2. > Can you please clarify? > > Thanks, > > Eugene > > -----Original Message----- > From: Richard Biener <richard.guenther@gmail.com> > Sent: Thursday, December 10, 2020 12:21 AM > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > Cc: gcc-patches@gcc.gnu.org > Subject: Re: Optimize combination of comparisons to dec+compare > > On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > This patch adds a pattern for optimizing x < y || x == XXX_MIN to x > > <= > > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. > > Do we already handle x < y || x <= CST to x <= y - CST? > That is, the XXX_MIN case is just a special-case of generic anti-range testing? For anti-range testing with signed types we pun to unsigned when possible. > > > This fixes pr96674. > > > > Tested on x86_64-pc-linux-gnu. > > > > For this function > > > > bool f(unsigned a, unsigned b) > > { > > return (b == 0) | (a < b); > > } > > > > the code without the patch is > > > > test esi,esi > > sete al > > cmp esi,edi > > seta dl > > or eax,edx > > ret > > > > the code with the patch is > > > > sub esi,0x1 > > cmp esi,edi > > setae al > > ret > > > > Eugene > > > > gcc/ > > PR tree-optimization/96674 > > * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 > > > > gcc/testsuite > > * gcc.dg/pr96674.c: New test. > > [-- Attachment #2: 0002-Optimize-combination-of-comparisons-to-dec-compare.patch --] [-- Type: application/octet-stream, Size: 3172 bytes --] From 689f3becbc6f6d7265c7b6fc4367910c82997fd4 Mon Sep 17 00:00:00 2001 From: Eugene Rozenfeld <erozen@microsoft.com> Date: Wed, 9 Dec 2020 16:44:25 -0800 Subject: [PATCH] Optimize combination of comparisons to dec+compare This patch adds patterns for optimizing x < y || y == XXX_MIN to x <= y-1 x >= y && y != XXX_MIN to x > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. This fixes pr96674. Tested on x86_64-pc-linux-gnu. For this function bool f(unsigned a, unsigned b) { return (b == 0) | (a < b); } the code without the patch is test esi,esi sete al cmp esi,edi seta dl or eax,edx ret the code with the patch is sub esi,0x1 cmp esi,edi setae al ret gcc/ PR tree-optimization/96674 * match.pd: New patterns: x < y || y == XXX_MIN --> x <= y - 1 x >= y && y != XXX_MIN --> x > y - 1 gcc/testsuite * gcc.dg/pr96674.c: New tests. --- gcc/match.pd | 14 ++++++++++++ gcc/testsuite/gcc.dg/pr96674.c | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr96674.c diff --git a/gcc/match.pd b/gcc/match.pd index 6f7b41fe0ff..cc1a876f0f2 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2147,6 +2147,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (eqne == NE_EXPR) { constant_boolean_node (true, type); })))) +/* y == XXX_MIN || x < y --> x <= y - 1 */ +(simplify + (bit_ior:c (eq:s @1 min_value) (lt:s @0 @1)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) + (le @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))) + +/* y != XXX_MIN && x >= y --> x > y - 1 */ +(simplify + (bit_and:c (ne:s @1 min_value) (ge:s @0 @1)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1)) + && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@1))) + (gt @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))) + /* Convert (X == CST1) && (X OP2 CST2) to a known value based on CST1 OP2 CST2. Similarly for (X != CST1). */ diff --git a/gcc/testsuite/gcc.dg/pr96674.c b/gcc/testsuite/gcc.dg/pr96674.c new file mode 100644 index 00000000000..194ce2e6352 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr96674.c @@ -0,0 +1,40 @@ +/* { dg-do run } */ +/* { dg-options "-O -fdump-tree-optimized -fwrapv" } */ + +#include <limits.h> +#include <stdbool.h> + +bool __attribute__ ((noipa)) test1 (unsigned a, unsigned b) +{ + return (b == 0) | (a < b); +} + +bool __attribute__ ((noipa)) test2 (int a, int b) +{ + return (b == INT_MIN) | (a < b); +} + +bool __attribute__ ((noipa)) test3 (unsigned a, unsigned b) +{ + return (b != 0) & (a >= b); +} + +bool __attribute__ ((noipa)) test4 (int a, int b) +{ + return (b != INT_MIN) & (a >= b); +} + +int main() +{ + if (!test1 (1, 0) || !test1 (1, 2) || test1 (2, 1) || + !test2 (1, INT_MIN) || !test2 (1, 2) || test2 (2, 1) || + test3 (1, 0) || test3 (1, 2) || !test3 (2, 1) || + test4 (1, INT_MIN) || test4 (1, 2) || !test4 (2, 1)) { + __builtin_abort(); + } + + return 0; +} + +/* { dg-final { scan-tree-dump-times "\\+ 4294967295;" 2 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "\\+ -1;" 2 "optimized" } } */ -- 2.17.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare 2021-01-14 21:04 ` [EXTERNAL] " Eugene Rozenfeld @ 2021-01-15 11:54 ` Richard Biener 2021-01-20 1:32 ` Eugene Rozenfeld 0 siblings, 1 reply; 6+ messages in thread From: Richard Biener @ 2021-01-15 11:54 UTC (permalink / raw) To: Eugene Rozenfeld; +Cc: gabravier, jakub, gcc-patches On Thu, Jan 14, 2021 at 10:04 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > I got more feedback for the patch from Gabriel Ravier and Jakub Jelinek in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96674 and re-worked it accordingly. > > The changes from the previous patch are: > 1. Switched the tests to use __attribute__((noipa)) instead of __attribute__((noinline)) . > 2. Fixed a type in the pattern comment. > 3. Added :c for top-level bit_ior expression. > 4. Added :s for the subexpressions. > 5. Added a pattern for the negated expression: > x >= y && y != XXX_MIN --> x > y - 1 > and the corresponding tests. > > The new patch is attached. OK. Thanks, Richard. > Eugene > > -----Original Message----- > From: Richard Biener <richard.guenther@gmail.com> > Sent: Tuesday, January 5, 2021 4:21 AM > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > Cc: gcc-patches@gcc.gnu.org > Subject: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare > > On Mon, Jan 4, 2021 at 9:50 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > > > Ping. > > > > -----Original Message----- > > From: Eugene Rozenfeld > > Sent: Tuesday, December 22, 2020 3:01 PM > > To: Richard Biener <richard.guenther@gmail.com>; > > gcc-patches@gcc.gnu.org > > Subject: RE: Optimize combination of comparisons to dec+compare > > > > Re-sending my question and re-attaching the patch. > > > > Richard, can you please clarify your feedback? > > Hmm, OK. > > The patch is OK. > > Thanks, > Richard. > > > > Thanks, > > > > Eugene > > > > -----Original Message----- > > From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of > > Eugene Rozenfeld via Gcc-patches > > Sent: Tuesday, December 15, 2020 2:06 PM > > To: Richard Biener <richard.guenther@gmail.com> > > Cc: gcc-patches@gcc.gnu.org > > Subject: [EXTERNAL] Re: Optimize combination of comparisons to > > dec+compare > > > > Richard, > > > > > Do we already handle x < y || x <= CST to x <= y - CST? > > > > That is an invalid transformation: e.g., consider x=3, y=4, CST=2. > > Can you please clarify? > > > > Thanks, > > > > Eugene > > > > -----Original Message----- > > From: Richard Biener <richard.guenther@gmail.com> > > Sent: Thursday, December 10, 2020 12:21 AM > > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > > Cc: gcc-patches@gcc.gnu.org > > Subject: Re: Optimize combination of comparisons to dec+compare > > > > On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > > > This patch adds a pattern for optimizing x < y || x == XXX_MIN to x > > > <= > > > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. > > > > Do we already handle x < y || x <= CST to x <= y - CST? > > That is, the XXX_MIN case is just a special-case of generic anti-range testing? For anti-range testing with signed types we pun to unsigned when possible. > > > > > This fixes pr96674. > > > > > > Tested on x86_64-pc-linux-gnu. > > > > > > For this function > > > > > > bool f(unsigned a, unsigned b) > > > { > > > return (b == 0) | (a < b); > > > } > > > > > > the code without the patch is > > > > > > test esi,esi > > > sete al > > > cmp esi,edi > > > seta dl > > > or eax,edx > > > ret > > > > > > the code with the patch is > > > > > > sub esi,0x1 > > > cmp esi,edi > > > setae al > > > ret > > > > > > Eugene > > > > > > gcc/ > > > PR tree-optimization/96674 > > > * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 > > > > > > gcc/testsuite > > > * gcc.dg/pr96674.c: New test. > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare 2021-01-15 11:54 ` Richard Biener @ 2021-01-20 1:32 ` Eugene Rozenfeld 2021-01-20 15:33 ` Richard Biener 0 siblings, 1 reply; 6+ messages in thread From: Eugene Rozenfeld @ 2021-01-20 1:32 UTC (permalink / raw) To: Richard Biener; +Cc: gabravier, jakub, gcc-patches Richard, Can you please commit this patch for me? I don't have write access yet, I'm still working on getting copyright assignment/disclaimer signed by my employer. Thanks, Eugene -----Original Message----- From: Richard Biener <richard.guenther@gmail.com> Sent: Friday, January 15, 2021 3:55 AM To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> Cc: gabravier@gmail.com; jakub@gcc.gnu.org; gcc-patches@gcc.gnu.org Subject: Re: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare On Thu, Jan 14, 2021 at 10:04 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > I got more feedback for the patch from Gabriel Ravier and Jakub Jelinek in https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D96674&data=04%7C01%7CEugene.Rozenfeld%40microsoft.com%7Cf4b1e41de6b4469fd3bb08d8b94c5a20%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637463084866262315%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2Fc77uS%2BNlNGmXwOmK729BByEW0VDiq1HEe8BA7DpI30%3D&reserved=0 and re-worked it accordingly. > > The changes from the previous patch are: > 1. Switched the tests to use __attribute__((noipa)) instead of __attribute__((noinline)) . > 2. Fixed a type in the pattern comment. > 3. Added :c for top-level bit_ior expression. > 4. Added :s for the subexpressions. > 5. Added a pattern for the negated expression: > x >= y && y != XXX_MIN --> x > y - 1 > and the corresponding tests. > > The new patch is attached. OK. Thanks, Richard. > Eugene > > -----Original Message----- > From: Richard Biener <richard.guenther@gmail.com> > Sent: Tuesday, January 5, 2021 4:21 AM > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > Cc: gcc-patches@gcc.gnu.org > Subject: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination > of comparisons to dec+compare > > On Mon, Jan 4, 2021 at 9:50 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > > > Ping. > > > > -----Original Message----- > > From: Eugene Rozenfeld > > Sent: Tuesday, December 22, 2020 3:01 PM > > To: Richard Biener <richard.guenther@gmail.com>; > > gcc-patches@gcc.gnu.org > > Subject: RE: Optimize combination of comparisons to dec+compare > > > > Re-sending my question and re-attaching the patch. > > > > Richard, can you please clarify your feedback? > > Hmm, OK. > > The patch is OK. > > Thanks, > Richard. > > > > Thanks, > > > > Eugene > > > > -----Original Message----- > > From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of > > Eugene Rozenfeld via Gcc-patches > > Sent: Tuesday, December 15, 2020 2:06 PM > > To: Richard Biener <richard.guenther@gmail.com> > > Cc: gcc-patches@gcc.gnu.org > > Subject: [EXTERNAL] Re: Optimize combination of comparisons to > > dec+compare > > > > Richard, > > > > > Do we already handle x < y || x <= CST to x <= y - CST? > > > > That is an invalid transformation: e.g., consider x=3, y=4, CST=2. > > Can you please clarify? > > > > Thanks, > > > > Eugene > > > > -----Original Message----- > > From: Richard Biener <richard.guenther@gmail.com> > > Sent: Thursday, December 10, 2020 12:21 AM > > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > > Cc: gcc-patches@gcc.gnu.org > > Subject: Re: Optimize combination of comparisons to dec+compare > > > > On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > > > This patch adds a pattern for optimizing x < y || x == XXX_MIN to > > > x <= > > > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. > > > > Do we already handle x < y || x <= CST to x <= y - CST? > > That is, the XXX_MIN case is just a special-case of generic anti-range testing? For anti-range testing with signed types we pun to unsigned when possible. > > > > > This fixes pr96674. > > > > > > Tested on x86_64-pc-linux-gnu. > > > > > > For this function > > > > > > bool f(unsigned a, unsigned b) > > > { > > > return (b == 0) | (a < b); > > > } > > > > > > the code without the patch is > > > > > > test esi,esi > > > sete al > > > cmp esi,edi > > > seta dl > > > or eax,edx > > > ret > > > > > > the code with the patch is > > > > > > sub esi,0x1 > > > cmp esi,edi > > > setae al > > > ret > > > > > > Eugene > > > > > > gcc/ > > > PR tree-optimization/96674 > > > * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 > > > > > > gcc/testsuite > > > * gcc.dg/pr96674.c: New test. > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare 2021-01-20 1:32 ` Eugene Rozenfeld @ 2021-01-20 15:33 ` Richard Biener 0 siblings, 0 replies; 6+ messages in thread From: Richard Biener @ 2021-01-20 15:33 UTC (permalink / raw) To: Eugene Rozenfeld; +Cc: gabravier, jakub, gcc-patches On Wed, Jan 20, 2021 at 2:32 AM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > Richard, > > Can you please commit this patch for me? I don't have write access yet, I'm still working on getting copyright assignment/disclaimer signed by my employer. Done after re-bootstrapping/testing on x86-64-linux. Richard. > Thanks, > > Eugene > > -----Original Message----- > From: Richard Biener <richard.guenther@gmail.com> > Sent: Friday, January 15, 2021 3:55 AM > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > Cc: gabravier@gmail.com; jakub@gcc.gnu.org; gcc-patches@gcc.gnu.org > Subject: Re: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare > > On Thu, Jan 14, 2021 at 10:04 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > > > I got more feedback for the patch from Gabriel Ravier and Jakub Jelinek in https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgcc.gnu.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D96674&data=04%7C01%7CEugene.Rozenfeld%40microsoft.com%7Cf4b1e41de6b4469fd3bb08d8b94c5a20%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637463084866262315%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2Fc77uS%2BNlNGmXwOmK729BByEW0VDiq1HEe8BA7DpI30%3D&reserved=0 and re-worked it accordingly. > > > > The changes from the previous patch are: > > 1. Switched the tests to use __attribute__((noipa)) instead of __attribute__((noinline)) . > > 2. Fixed a type in the pattern comment. > > 3. Added :c for top-level bit_ior expression. > > 4. Added :s for the subexpressions. > > 5. Added a pattern for the negated expression: > > x >= y && y != XXX_MIN --> x > y - 1 > > and the corresponding tests. > > > > The new patch is attached. > > OK. > > Thanks, > Richard. > > > Eugene > > > > -----Original Message----- > > From: Richard Biener <richard.guenther@gmail.com> > > Sent: Tuesday, January 5, 2021 4:21 AM > > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > > Cc: gcc-patches@gcc.gnu.org > > Subject: [EXTERNAL] Re: [PATCH][tree-optimization]Optimize combination > > of comparisons to dec+compare > > > > On Mon, Jan 4, 2021 at 9:50 PM Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> wrote: > > > > > > Ping. > > > > > > -----Original Message----- > > > From: Eugene Rozenfeld > > > Sent: Tuesday, December 22, 2020 3:01 PM > > > To: Richard Biener <richard.guenther@gmail.com>; > > > gcc-patches@gcc.gnu.org > > > Subject: RE: Optimize combination of comparisons to dec+compare > > > > > > Re-sending my question and re-attaching the patch. > > > > > > Richard, can you please clarify your feedback? > > > > Hmm, OK. > > > > The patch is OK. > > > > Thanks, > > Richard. > > > > > > > Thanks, > > > > > > Eugene > > > > > > -----Original Message----- > > > From: Gcc-patches <gcc-patches-bounces@gcc.gnu.org> On Behalf Of > > > Eugene Rozenfeld via Gcc-patches > > > Sent: Tuesday, December 15, 2020 2:06 PM > > > To: Richard Biener <richard.guenther@gmail.com> > > > Cc: gcc-patches@gcc.gnu.org > > > Subject: [EXTERNAL] Re: Optimize combination of comparisons to > > > dec+compare > > > > > > Richard, > > > > > > > Do we already handle x < y || x <= CST to x <= y - CST? > > > > > > That is an invalid transformation: e.g., consider x=3, y=4, CST=2. > > > Can you please clarify? > > > > > > Thanks, > > > > > > Eugene > > > > > > -----Original Message----- > > > From: Richard Biener <richard.guenther@gmail.com> > > > Sent: Thursday, December 10, 2020 12:21 AM > > > To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com> > > > Cc: gcc-patches@gcc.gnu.org > > > Subject: Re: Optimize combination of comparisons to dec+compare > > > > > > On Thu, Dec 10, 2020 at 1:52 AM Eugene Rozenfeld via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > > > > > This patch adds a pattern for optimizing x < y || x == XXX_MIN to > > > > x <= > > > > y-1 if y is an integer with TYPE_OVERFLOW_WRAPS. > > > > > > Do we already handle x < y || x <= CST to x <= y - CST? > > > That is, the XXX_MIN case is just a special-case of generic anti-range testing? For anti-range testing with signed types we pun to unsigned when possible. > > > > > > > This fixes pr96674. > > > > > > > > Tested on x86_64-pc-linux-gnu. > > > > > > > > For this function > > > > > > > > bool f(unsigned a, unsigned b) > > > > { > > > > return (b == 0) | (a < b); > > > > } > > > > > > > > the code without the patch is > > > > > > > > test esi,esi > > > > sete al > > > > cmp esi,edi > > > > seta dl > > > > or eax,edx > > > > ret > > > > > > > > the code with the patch is > > > > > > > > sub esi,0x1 > > > > cmp esi,edi > > > > setae al > > > > ret > > > > > > > > Eugene > > > > > > > > gcc/ > > > > PR tree-optimization/96674 > > > > * match.pd: New pattern x < y || x == XXX_MIN --> x <= y - 1 > > > > > > > > gcc/testsuite > > > > * gcc.dg/pr96674.c: New test. > > > > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-01-20 15:33 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-01-04 20:50 [PATCH][tree-optimization]Optimize combination of comparisons to dec+compare Eugene Rozenfeld 2021-01-05 12:21 ` Richard Biener 2021-01-14 21:04 ` [EXTERNAL] " Eugene Rozenfeld 2021-01-15 11:54 ` Richard Biener 2021-01-20 1:32 ` Eugene Rozenfeld 2021-01-20 15:33 ` Richard Biener
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).