public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/c++-modules] tree-optimization/94234 - add pattern for ptr-diff on addresses with same offset Date: Fri, 28 Aug 2020 15:56:28 +0000 (GMT) [thread overview] Message-ID: <20200828155628.5C1903851C27@sourceware.org> (raw) https://gcc.gnu.org/g:459f6f68a75fe88e7c8309ca8ad3244a532b0d8e commit 459f6f68a75fe88e7c8309ca8ad3244a532b0d8e Author: Feng Xue <fxue@os.amperecomputing.com> Date: Mon Jun 1 11:57:35 2020 +0800 tree-optimization/94234 - add pattern for ptr-diff on addresses with same offset 2020-08-19 Feng Xue <fxue@os.amperecomputing.com> gcc/ PR tree-optimization/94234 * match.pd ((PTR_A + OFF) - (PTR_B + OFF)) -> (PTR_A - PTR_B): New simplification. gcc/testsuite/ PR tree-optimization/94234 * gcc.dg/pr94234-1.c: New test. Diff: --- gcc/match.pd | 3 +++ gcc/testsuite/gcc.dg/pr94234-1.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index c3b88168ac4..2cffcae3d8b 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2549,6 +2549,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && TREE_CODE (@2) == INTEGER_CST && tree_int_cst_sign_bit (@2) == 0)) (minus (convert @1) (convert @2))))) + (simplify + (pointer_diff (pointer_plus @0 @2) (pointer_plus @1 @2)) + (pointer_diff @0 @1)) (simplify (pointer_diff (pointer_plus @@0 @1) (pointer_plus @0 @2)) /* The second argument of pointer_plus must be interpreted as signed, and diff --git a/gcc/testsuite/gcc.dg/pr94234-1.c b/gcc/testsuite/gcc.dg/pr94234-1.c new file mode 100644 index 00000000000..d85563b32da --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr94234-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop1" } */ + +typedef __INTPTR_TYPE__ ssize_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; + +ptrdiff_t foo (char *a, ssize_t n, ssize_t m) +{ + char *b1 = a + 8 * n; + char *b2 = a + 8 * (n + 1); + + return (b1 + m) - (b2 + m); +} + +/* { dg-final { scan-tree-dump-times "return -8;" 1 "forwprop1" } } */
reply other threads:[~2020-08-28 15:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200828155628.5C1903851C27@sourceware.org \ --to=nathan@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).