This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[committed] Tune pointer-plus folding
- From: Tom de Vries <Tom_deVries at mentor dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Jakub Jelinek <jakub at redhat dot com>, "gcc-patches at gnu dot org" <gcc-patches at gnu dot org>
- Date: Sat, 31 Oct 2015 10:44:21 +0100
- Subject: [committed] Tune pointer-plus folding
- Authentication-results: sourceware.org; auth=none
- References: <5631F735 dot 2080604 at mentor dot com> <CAFiYyc27rK3T8Q42o_EbZOVo1Phs=DHx9TPM8C3UebvXvROERQ at mail dot gmail dot com> <56333152 dot 7040403 at mentor dot com> <CAFiYyc0jGUOrDQYKu4+Nt4F5hwnHhgR8zH_ppfmuO5JcN=vvzw at mail dot gmail dot com>
[ 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
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