This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Eliminate location wrappers in tree_nop_conversion/STRIP_NOPS
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>, Jason Merrill <jason at redhat dot com>
- Cc: Nathan Sidwell <nathan at acm dot org>, Richard Biener <richard dot guenther at gmail dot com>, gcc-patches List <gcc-patches at gcc dot gnu dot org>, David Malcolm <dmalcolm at redhat dot com>
- Date: Tue, 19 Dec 2017 19:44:38 -0500
- Subject: [PATCH] Eliminate location wrappers in tree_nop_conversion/STRIP_NOPS
- Authentication-results: sourceware.org; auth=none
- References: <20171219220321.GD2353@tucnak>
On Tue, 2017-12-19 at 23:03 +0100, Jakub Jelinek wrote:
> On Tue, Dec 19, 2017 at 04:59:34PM -0500, Jason Merrill wrote:
> > > Or do you mean it should strip just the special VIEW_CONVERT_EXPR
> > > that has type identical to the operand's type?
> >
> > That; interpreting something as the same type seems like a nop.
>
> Ok, that makes sense.
>
> Jakub
Thanks.
How does the following look?
Bootstrap®rtest in progress; OK for trunk if it passes? (once the rest of
the kit is approved, of course)
gcc/ChangeLog:
* tree.c (tree_nop_conversion): Return true for location wrapper
nodes.
(selftest::check_strip_nops): New function.
(selftest::test_location_wrappers): Verify that STRIP_NOPS removes
wrappers.
---
gcc/tree.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/gcc/tree.c b/gcc/tree.c
index 2d14916..9c9bb77 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -11889,6 +11889,8 @@ tree_nop_conversion (const_tree exp)
{
tree outer_type, inner_type;
+ if (location_wrapper_p (exp))
+ return true;
if (!CONVERT_EXPR_P (exp)
&& TREE_CODE (exp) != NON_LVALUE_EXPR)
return false;
@@ -14208,6 +14210,17 @@ test_vector_cst_patterns ()
check_vector_cst_fill (elements, build_vector (vector_type, elements), 4);
}
+/* Verify that STRIP_NOPS (NODE) is EXPECTED.
+ Helper function for test_location_wrappers, to deal with STRIP_NOPS
+ modifying its argument in-place. */
+
+static void
+check_strip_nops (tree node, tree expected)
+{
+ STRIP_NOPS (node);
+ ASSERT_EQ (expected, node);
+}
+
/* Verify location wrappers. */
static void
@@ -14242,6 +14255,10 @@ test_location_wrappers ()
tree r_cast = build1 (NON_LVALUE_EXPR, integer_type_node, int_var);
ASSERT_FALSE (location_wrapper_p (r_cast));
ASSERT_EQ (r_cast, tree_strip_any_location_wrapper (r_cast));
+
+ /* Verify that STRIP_NOPS removes wrappers. */
+ check_strip_nops (wrapped_int_cst, int_cst);
+ check_strip_nops (wrapped_int_var, int_var);
}
/* Run all of the selftests within this file. */
--
1.8.5.3