This is the mail archive of the gcc-patches@gcc.gnu.org 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]

Re: [tuples][patch] Don't create GIMPLE_CONDs that trap


On 05/02/08 09:16, Rafael Espindola wrote:
The attached patch fixes the problem we were having with a BB having
more than 2 output edges. It includes a fix for the problem Doug's
observed on tree_could_trap_p.

OK if it bootstraps and passes regression tests.

There are two bugs in mainline:


- tree_could_throw_p() is not diving deep enough. It sees a COND_EXPR and it immediately returns false. On tuples, however, we see the flattened comparison directly.

- Even if it dove into the comparison, mainline still will return false from tree_could_throw_p(). The reason now is that the comparison itself (GE_EXPR) has type bool, not float. Therefore, tree_could_trap_p never sets honor_nans to true, and it still returns false.

The right approach here is to reject trapping floating point comparisons in is_gimple_condexpr(). However, this will not work now. If it's true that floating point comparisons may trap, then the code in tree_could_trap_p() in trunk and tuples is wrong. The code does not check the type of the operands, it checks the type of the whole expression.

In the case of t = <GE_EXPR, float, float>, the type of 't' is boolean, not float. So, for booleans, tree_could_trap_p should check the type of the operands.

Now, the other question is: how have we gotten away with this for so long? We've allowed potentially trapping floating point comparisons in mainline for ever, basically.

This (untested) patch should fix the problem. Rafael could you try this one?

Thanks. Diego.

Index: tree-gimple.c
===================================================================
--- tree-gimple.c       (revision 134863)
+++ tree-gimple.c       (working copy)
@@ -204,7 +204,9 @@ is_gimple_lvalue (tree t)
 bool
 is_gimple_condexpr (tree t)
 {
-  return (is_gimple_val (t) || COMPARISON_CLASS_P (t));
+  return ((is_gimple_val (t)
+          || COMPARISON_CLASS_P (t))
+          && !tree_could_trap_p (t));
 }

 /*  Return true if T is something whose address can be taken.  */
Index: tree-eh.c
===================================================================
--- tree-eh.c   (revision 134863)
+++ tree-eh.c   (working copy)
@@ -2174,12 +2174,18 @@ tree_could_trap_p (tree expr)

if (t)
{
- fp_operation = FLOAT_TYPE_P (t);
+ bool fp_compare;
+
+ fp_compare = (COMPARISON_CLASS_P (expr)
+ && (FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 0)))
+ || FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 1)))));
+ fp_operation = FLOAT_TYPE_P (t) || fp_compare;
honor_trapv = INTEGRAL_TYPE_P (t) && TYPE_OVERFLOW_TRAPS (t);
}


   if (TREE_CODE_CLASS (code) == tcc_binary)
     div = TREE_OPERAND (expr, 1);
+
   if (operation_could_trap_p (code, fp_operation, honor_trapv, div))
     return true;


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