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.
Confirmed.
A patch (with following long discussion) has been proposed here: http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01495.html W.
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.
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.