https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122502

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com,
                   |                            |rguenth at gcc dot gnu.org

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is this loop:
```
          FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, rslt)
            {
              gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
              if (!stmt_can_throw_internal (cfun, use_stmt)
                  && fold_stmt (&gsi, follow_all_ssa_edges))
                update_stmt (gsi_stmt (gsi));
            }
```
vs this loop (with the same SSA_NAME, s4_31):
```
  // Loop over each immediate use and see if it has an inferred range.
  FOR_EACH_IMM_USE_FAST (use_p, iter, name)
    {
      gimple *s = USE_STMT (use_p);
      gimple_infer_range infer (s, m_query);
      for (unsigned x = 0; x < infer.num (); x++)
        {
          if (name == infer.name (x))
            add_range (name, s, infer.range (x));
        }
    }
```

Which is inside the ranger code.
Which is because the ranger is called from this pattern:
```
 (simplify
  (cmp (nop_convert? @0) integer_zerop)
  (if (tree_expr_nonzero_p (@0))
   { constant_boolean_node (cmp == NE_EXPR, type); }))
```

tree_expr_nonzero_p calls:
```
    case SSA_NAME:
      if (!INTEGRAL_TYPE_P (TREE_TYPE (t)))
        break;
      return expr_not_equal_to (t, wi::zero (TYPE_PRECISION (TREE_TYPE (t))));
```
expr_not_equal_to does:
      get_range_query (cfun)->range_of_expr (vr, t);


on s4_31 .

I am not going to be able to solve this one by myself.

A few questions here which points to the best way of solving this:
Is calling fold_stmt inside a FOR_EACH_IMM_USE_STMT valid (or is it only valid
if no ranger is turned on; there are a few other places which does this and
might need to change too)?
Or is valid is match pattern ok to call into tree_expr_nonzero_p/ranger?
Or is what the ranger doing wrong and should instead use some other way to
iterate the uses?

Reply via email to