Eliminate location wrappers in tree_nop_conversion/STRIP_NOPS

Message ID 1513730678-53275-1-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series
  • Eliminate location wrappers in tree_nop_conversion/STRIP_NOPS
Related show

Commit Message

David Malcolm Dec. 20, 2017, 12:44 a.m.
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&regrtest 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(+)

-- 
1.8.5.3

Comments

Jeff Law Dec. 20, 2017, 4:27 a.m. | #1
On 12/19/2017 05:44 PM, David Malcolm wrote:
> 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&regrtest 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.

OK.
jeff

Patch

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.  */