[PATCH] Make host_integerp pure and inline tree_low_cst

Jakub Jelinek jakub@redhat.com
Tue Aug 17 17:19:00 GMT 2010


Hi!

In many places we call host_integerp and if it succeeds, call
tree_low_cst, which again calls host_integerp.
The following patch makes host_integerp pure when not doing
tree checking (otherwise it can fail if t's type is error_mark_node
or some other non-type) and inlines tree_low_cst in that case too.
Tested with both --disable-checking and --enable-checking=release.
With the former obviously .text section shrunk, with release checking
it grew tiny bit:
			[1]	[2]	.text size
cc1plus -m64 before	281	269	0x730a3c
cc1plus -m64 after	417	7	0x73143c
cc1plus -m32 before	274	275	0x6c7ca0
cc1plus -m32 after	411	10	0x6c7f10

[1] number of call host_integerp insns
[2] number of call tree_low_cst insns

As can be seen from the numbers, in more than half of the cases
gcc actually has been able to optimize that gcc_assert from the inline
tree_low_cst away.

Ok for trunk?

2010-08-17  Jakub Jelinek  <jakub@redhat.com>

	* tree.h (host_integerp): Add ATTRIBUTE_PURE when not
	ENABLE_TREE_CHECKING.
	(tree_low_cst): Add inline version for !ENABLE_TREE_CHECKING
	and GCC >= 4.3.

--- gcc/tree.h.jj	2010-08-16 19:24:24.000000000 +0200
+++ gcc/tree.h	2010-08-17 16:14:59.000000000 +0200
@@ -4099,8 +4099,20 @@ extern int attribute_list_contained (con
 extern int tree_int_cst_equal (const_tree, const_tree);
 extern int tree_int_cst_lt (const_tree, const_tree);
 extern int tree_int_cst_compare (const_tree, const_tree);
-extern int host_integerp (const_tree, int);
+extern int host_integerp (const_tree, int)
+#ifndef ENABLE_TREE_CHECKING
+  ATTRIBUTE_PURE /* host_integerp is pure only when checking is disabled.  */
+#endif
+  ;
 extern HOST_WIDE_INT tree_low_cst (const_tree, int);
+#if !defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 4003)
+extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT
+tree_low_cst (const_tree t, int pos)
+{
+  gcc_assert (host_integerp (t, pos));
+  return TREE_INT_CST_LOW (t);
+}
+#endif
 extern int tree_int_cst_msb (const_tree);
 extern int tree_int_cst_sgn (const_tree);
 extern int tree_int_cst_sign_bit (const_tree);

	Jakub



More information about the Gcc-patches mailing list