trans.c (build_binary_op_trapv): Avoid emitting overflow check for constant result.
authorGeert Bosch <bosch@adacore.com>
Fri, 7 Nov 2008 09:39:38 +0000 (09:39 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 7 Nov 2008 09:39:38 +0000 (09:39 +0000)
* gcc-interface/trans.c (build_binary_op_trapv): Avoid emitting
overflow check for constant result.

From-SVN: r141666

gcc/ada/ChangeLog
gcc/ada/gcc-interface/trans.c

index f9d8993..68f0623 100644 (file)
@@ -1,5 +1,10 @@
 2008-11-07  Geert Bosch  <bosch@adacore.com>
 
+       * gcc-interface/trans.c (build_binary_op_trapv): Avoid emitting
+       overflow check for constant result.
+
+2008-11-07  Geert Bosch  <bosch@adacore.com>
+
        * gcc-interface/trans.c (build_binary_op_trapv): Use more efficient
        overflow check for addition/subtraction if neither operand is constant.
 
index 5d56ef8..aca7167 100644 (file)
@@ -6146,6 +6146,10 @@ build_binary_op_trapv (enum tree_code code,
 
   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);