@@ -2446,12 +2446,13 @@ gimple_could_trap_p_1 (const gimple *s, bool include_mem, bool include_stores)
op = gimple_assign_rhs_code (s);
/* COND_EXPR does not trap. */
- if (op == COND_EXPR)
+ if (op == COND_EXPR || op == VEC_COND_EXPR)
return false;
/* For comparisons we need to check rhs operand types instead of lhs type
(which is BOOLEAN_TYPE). */
- if (TREE_CODE_CLASS (op) == tcc_comparison)
+ if (TREE_CODE_CLASS (op) == tcc_comparison
+ || op == FIX_TRUNC_EXPR)
t = TREE_TYPE (gimple_assign_rhs1 (s));
else
t = TREE_TYPE (gimple_assign_lhs (s));
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do run { target *-*-*gnu* } } */
+/* { dg-additional-options "-D_GNU_SOURCE" } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#include <fenv.h>
+#include <stdlib.h>
+
+__attribute__((noipa)) void maybe_exit (int c) { if (c) exit (0); }
+
+__attribute__((noipa)) int f (double a, double b, int c)
+{
+ int r;
+ if (c > 5)
+ {
+ maybe_exit (c);
+ r = a < b;
+ }
+ else
+ r = (a < b) * c + 1;
+ return r;
+}
+
+int main (void)
+{
+ feenableexcept (FE_INVALID);
+ f (__builtin_nan (""), 1.0, 7);
+ return 1;
+}
@@ -7004,11 +7004,18 @@ vn_nary_may_trap (vn_nary_op_t nary)
bool handled, ret;
unsigned i;
+ if (nary->opcode == COND_EXPR || nary->opcode == VEC_COND_EXPR)
+ return false;
+
if (TREE_CODE_CLASS (nary->opcode) == tcc_comparison
|| TREE_CODE_CLASS (nary->opcode) == tcc_unary
|| TREE_CODE_CLASS (nary->opcode) == tcc_binary)
{
- type = nary->type;
+ if (TREE_CODE_CLASS (nary->opcode) == tcc_comparison
+ || nary->opcode == FIX_TRUNC_EXPR)
+ type = TREE_TYPE (nary->op[0]);
+ else
+ type = nary->type;
fp_operation = FLOAT_TYPE_P (type);
if (fp_operation)
{