public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	"gcc-patches@gnu.org"	<gcc-patches@gnu.org>
Subject: [committed] Tune pointer-plus folding
Date: Sat, 31 Oct 2015 10:24:00 -0000	[thread overview]
Message-ID: <56348D75.4040006@mentor.com> (raw)
In-Reply-To: <CAFiYyc0jGUOrDQYKu4+Nt4F5hwnHhgR8zH_ppfmuO5JcN=vvzw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

[ was: Re: [PATCH] Allow more pointer-plus folding ]

On 30/10/15 10:24, Richard Biener wrote:
>>> I think the checks on TREE_OPERAND (arg0, 1) are bogus though
>>> >>and either we should unconditionally sink the conversion or only
>>> >>if a conversion on TREE_OPERAND (arg0, 0) vanishes (I prefer the
>>> >>latter).
>>> >>
>> >
>> >Like this? OK for trunk if bootstrap/reg-test succeeds?
> Ok with using CONVERT_EXPR_P (TREE_OPERAND (arg0, 0)) instead of
> an explicit NOP_EXPR check.

Committed to trunk as attached, with:
- fold-const.c comment updated, and
- two test-cases updated (where we do less folding than before).

And I've changed the title of the commit since although we do allow more 
folding in some cases, we allow less folding in other cases.

Thanks,
- Tom

[-- Attachment #2: 0001-Tune-pointer-plus-folding.patch --]
[-- Type: text/x-patch, Size: 3526 bytes --]

Tune pointer-plus folding

2015-10-30  Tom de Vries  <tom@codesourcery.com>

	* fold-const.c (fold_unary_loc): Tune POINTER_PLUS_EXPR folding.

	* gfortran.dg/assumed_type_2.f90: Update test.
	* gfortran.dg/no_arg_check_2.f90: Same.
---
 gcc/fold-const.c                             | 10 ++++------
 gcc/testsuite/gfortran.dg/assumed_type_2.f90 |  2 +-
 gcc/testsuite/gfortran.dg/no_arg_check_2.f90 |  2 +-
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index b9168f3..197ccfd 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -7755,14 +7755,12 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
 	    }
 	}
 
-      /* Convert (T1)(X p+ Y) into ((T1)X p+ Y), for pointer type,
-         when one of the new casts will fold away. Conservatively we assume
-	 that this happens when X or Y is NOP_EXPR or Y is INTEGER_CST. */
+      /* Convert (T1)(X p+ Y) into ((T1)X p+ Y), for pointer type, when the new
+	 cast (T1)X will fold away.  We assume that this happens when X itself
+	 is a cast.  */
       if (POINTER_TYPE_P (type)
 	  && TREE_CODE (arg0) == POINTER_PLUS_EXPR
-	  && (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
-	      || TREE_CODE (TREE_OPERAND (arg0, 0)) == NOP_EXPR
-	      || TREE_CODE (TREE_OPERAND (arg0, 1)) == NOP_EXPR))
+	  && CONVERT_EXPR_P (TREE_OPERAND (arg0, 0)))
 	{
 	  tree arg00 = TREE_OPERAND (arg0, 0);
 	  tree arg01 = TREE_OPERAND (arg0, 1);
diff --git a/gcc/testsuite/gfortran.dg/assumed_type_2.f90 b/gcc/testsuite/gfortran.dg/assumed_type_2.f90
index ec51b8b..f1a2074 100644
--- a/gcc/testsuite/gfortran.dg/assumed_type_2.f90
+++ b/gcc/testsuite/gfortran.dg/assumed_type_2.f90
@@ -155,7 +155,7 @@ end
 ! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(struct t2.0:. . restrict\\) array_t2_alloc.data" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(struct t3.0:. .\\) array_t3_ptr.data" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) array_class_t1_alloc._data.data" 1 "original" } }
-! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) array_class_t1_ptr._data.dat" 1 "original" } }a
+! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) \\(array_class_t1_ptr._data.dat" 1 "original" } }
 
 ! { dg-final { scan-tree-dump-times "sub_array_assumed \\(D" 3 "original" } }
 ! { dg-final { scan-tree-dump-times " = _gfortran_internal_pack \\(&parm" 1 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/no_arg_check_2.f90 b/gcc/testsuite/gfortran.dg/no_arg_check_2.f90
index 3645ded..b3fb468 100644
--- a/gcc/testsuite/gfortran.dg/no_arg_check_2.f90
+++ b/gcc/testsuite/gfortran.dg/no_arg_check_2.f90
@@ -137,7 +137,7 @@ end
 ! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(struct t2.0:. . restrict\\) array_t2_alloc.data" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "sub_scalar .&\\(.\\(struct t3.0:. .\\) array_t3_ptr.data" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) array_class_t1_alloc._data.data" 1 "original" } }
-! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) array_class_t1_ptr._data.dat" 1 "original" } }a
+! { dg-final { scan-tree-dump-times "sub_scalar .\\(struct t1 .\\) \\(array_class_t1_ptr._data.dat" 1 "original" } }
 
 ! { dg-final { scan-tree-dump-times "sub_array_assumed \\(D" 3 "original" } }
 ! { dg-final { scan-tree-dump-times " = _gfortran_internal_pack \\(&parm" 1 "original" } }
-- 
1.9.1


      reply	other threads:[~2015-10-31  9:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-29 11:00 [PATCH] Don't handle CAST_RESTRICT (PR tree-optimization/49279) Tom de Vries
2015-10-29 12:05 ` Richard Biener
2015-10-30  8:59   ` [PATCH] Allow more pointer-plus folding Tom de Vries
2015-10-30  9:29     ` Richard Biener
2015-10-31 10:24       ` Tom de Vries [this message]

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=56348D75.4040006@mentor.com \
    --to=tom_devries@mentor.com \
    --cc=gcc-patches@gnu.org \
    --cc=jakub@redhat.com \
    --cc=richard.guenther@gmail.com \
    /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: link
Be 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).