This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Ada] Avoid emitting overflow check for constant result
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 7 Nov 2008 10:41:33 +0100
- Subject: [Ada] Avoid emitting overflow check for constant result
This is a follow-up to
http://gcc.gnu.org/ml/gcc-patches/2008-07/msg02416.html
so no code generation change for the time being.
While checks would be optimized away, if the constant overflows, there would
be no way to warn the user. Now the constant is returned and the caller has
to check for TREE_OVERFLOW. This matches the behavior of build_binary_op.
Tested on i586-suse-linux, applied on the mainline.
2008-11-07 Geert Bosch <bosch@adacore.com>
* gcc-interface/trans.c (build_binary_op_trapv): Avoid emitting
overflow check for constant result.
--
Eric Botcazou
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c (revision 141665)
+++ gcc-interface/trans.c (working copy)
@@ -6146,6 +6146,10 @@ build_binary_op_trapv (enum tree_code co
gnu_expr = build_binary_op (code, gnu_type, lhs, rhs);
+ /* If we can fold the expression to a constant, just return it.
+ The caller will deal with overflow, no need to generate a check. */
+ if (TREE_CONSTANT (gnu_expr)) return gnu_expr;
+
check = fold_build3 (COND_EXPR, integer_type_node,
rhs_lt_zero, check_neg, check_pos);