Bug 17617 - Micro-optimize INTEGRAL_TYPE_P (or tree.def rather)
Summary: Micro-optimize INTEGRAL_TYPE_P (or tree.def rather)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P2 enhancement
Target Milestone: 4.0.0
Assignee: Nathan Sidwell
URL:
Keywords: compile-time-hog
Depends on:
Blocks:
 
Reported: 2004-09-22 19:06 UTC by Kazu Hirata
Modified: 2005-01-07 14:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-09-22 21:17:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2004-09-22 19:06:25 UTC
We can reorder some tree codes in tree.def so that
the four codes accepted by INTEGRAL_TYPE_P are all sequential.
That way, fold() will convert INTEGRAL_TYPE_P into a range comparison.
Comment 1 Andrew Pinski 2004-09-22 21:17:04 UTC
Confirmed.
Comment 2 Wolfgang Bangerth 2004-12-20 17:08:42 UTC
A patch (with following long discussion) has been proposed here: 
  http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01495.html 
 
W. 
Comment 3 Wolfgang Bangerth 2004-12-20 17:14:44 UTC
The question raised in several of the messages in that discussion 
is whether an enumeration of equality checks is converted into a 
range check if the tested values are consecutive. 
 
Here is the answer: 
-------------------- 
enum E  
{ 
      eins = 1, 
      zwei = 2, 
      drei = 3, 
      vier = 4, 
      fuenf= 5, 
      sechs= 6 
}; 
 
bool test_range (E e) 
{ 
  return e==drei || e==vier || e==fuenf; 
} 
------------------------ 
 
This is indeed compiled into a range check: 
_Z10test_range1E: 
	pushl	%ebp 
	movl	%esp, %ebp 
	movl	8(%ebp), %eax 
	popl	%ebp 
	subl	$3, %eax 
	cmpl	$2, %eax 
	setbe	%al 
	movzbl	%al, %eax 
	ret 
 
W. 
Comment 4 Nathan Sidwell 2004-12-21 17:43:06 UTC
2004-12-21  Nathan Sidwell  <nathan@codesourcery.com>

	* system.c (IN_RANGE): Use plain unsigned, not unsigned
	HOST_WIDE_INT.
	* tree.def (VOID_TYPE, INTEGER_TYPE, REAL_TYPE, COMPLEX_TYPE,
	VECTOR_TYPE, OFFSET_TYPE, ENUMERAL_TYPE, BOOLEAN_TYPE, CHAR_TYPE,
	POINTER_TYPE, REFERENCE_TYPE, METHOD_TYPE, FUNCTION_TYPE,
	FILE_TYPE, ARRAY_TYPE, RECORD_TYPE, UNION_TYPE,
	QUAL_UNION_TYPE): Reorder for better code efficiency.
	(CONST_DECL, TYPE_DECL, VAR_DECL, FIELD_DECL, PARM_DECL): Likewise.
	(INDIRECT_REF, ALIGN_INDIRECT_REF, MISALIGNED_INDIRECT_REF): Likewise.
	* tree.h (INDIRECT_REF_P): Reorder checks for better optimization.
	(IS_EXPR_CODE_CLASS): Use IN_RANGE.
	(INTEGRAL_TYPE_P, FLOAT_TYPE_P): Reorder checks for better
	optimization.

	* cp/cp-tree.def (TEMPLATE_TYPE_PARM,
	BOUND_TEMPLATE_TEMPLATE_PARM, TYPE_OF_TYPE, TYPENAME_TYPE): Reorder 
	for better code efficiency.
	* cp/cp-tree.h (CLASS_TYPE_P): Short circuit IS_AGGR_TYPE check.
	(CAN_HAVE_FULL_LANG_DECL_P): Reorder for better optimization.
	(INTEGRAL_CODE_P, CP_INTEGRAL_TYPE_P,
	INTEGRAL_OR_ENUMERATION_TYPE_P, SCALAR_TYPE_P,
	CP_AGGREGATE_TYPE_P, TYPE_PTROB_P, TYPE_REF_OBJ_P,
	TYPE_PTROBV_P): Likewise.