This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[JAVA PATCH] Minor tweak to java_check_reference
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org, <java-patches at gcc dot gnu dot org>
- Date: Sat, 27 Sep 2003 21:19:19 -0600 (MDT)
- Subject: [JAVA PATCH] Minor tweak to java_check_reference
The following patch makes a small improvement to java_check_reference
in expr.c. When creating NULL-pointer checks, we can take advantage
of the semantics of COND_EXPR to avoid wrapping the expression in a
COMPOUND_EXPR. COND_EXPR allows either the second or third operand
to have void type, indicating that that branch/arm either throws an
exception or calls a noreturn function, i.e. doesn't terminate
naturally. This behaviour/feature is used by similar bounds checking
code elsewhere in the compiler.
The advantage to using a COND_EXPR this way, rather than a
COMPOUND_EXPR, is that it enables more middle-end optimizations, both
in constant folding and during RTL generation. It also saves a little
space and may help tree-ssa.
The following patch has been tested on i686-pc-linux-gnu with a
complete "make bootstrap", all languages except treelang, and regression
tested with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-09-27 Roger Sayle <roger@eyesopen.com>
* expr.c (java_check_reference): Use the semantics of COND_EXPRs
with void-type branches instead of using a COMPOUND_EXPR.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.172
diff -c -3 -p -r1.172 expr.c
*** expr.c 21 Sep 2003 05:07:19 -0000 1.172
--- expr.c 27 Sep 2003 20:25:27 -0000
*************** java_check_reference (tree expr, int che
*** 695,709 ****
{
if (!flag_syntax_only && check)
{
- tree cond;
expr = save_expr (expr);
! cond = build (COND_EXPR, void_type_node,
build (EQ_EXPR, boolean_type_node, expr, null_pointer_node),
build (CALL_EXPR, void_type_node,
build_address_of (soft_nullpointer_node),
NULL_TREE, NULL_TREE),
! empty_stmt_node);
! expr = build (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
}
return expr;
--- 695,707 ----
{
if (!flag_syntax_only && check)
{
expr = save_expr (expr);
! expr = build (COND_EXPR, TREE_TYPE (expr),
build (EQ_EXPR, boolean_type_node, expr, null_pointer_node),
build (CALL_EXPR, void_type_node,
build_address_of (soft_nullpointer_node),
NULL_TREE, NULL_TREE),
! expr);
}
return expr;
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833