This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Handle boolean_type_node in constant_boolean_node

The following patch is an obvious micro-optimization to the middle-end's
constant_boolean_node that benefits the C++, Java and fortran front-ends.
Unlike the C front-end, which uses integer_type_node for its
truthvalue_type_node, these other front-ends use boolean_type_node.
By handling this common case in constant_boolean_node we typically
avoid a virtual function dispatch and lots of condititional tests to
determine that we only want to type convert an integer constant.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures (though the libjava
testsuite didn't look too healthy with or without this patch).

Committed to mainline as obvious.

2004-06-17  Roger Sayle  <>

	* fold-const.c (constant_boolean_node): Handle boolean_type_node
	directly, return either boolean_true_node or boolean_false_node.

Index: fold-const.c
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.399
diff -c -3 -p -r1.399 fold-const.c
*** fold-const.c	17 Jun 2004 20:19:57 -0000	1.399
--- fold-const.c	17 Jun 2004 23:04:08 -0000
*************** constant_boolean_node (int value, tree t
*** 4936,4941 ****
--- 4936,4943 ----
    if (type == integer_type_node)
      return value ? integer_one_node : integer_zero_node;
+   else if (type == boolean_type_node)
+     return value ? boolean_true_node : boolean_false_node;
    else if (TREE_CODE (type) == BOOLEAN_TYPE)
      return lang_hooks.truthvalue_conversion (value ? integer_one_node
  						   : integer_zero_node);

Roger Sayle,                         E-mail:
OpenEye Scientific Software,         WWW:
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]