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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Macleod from comment #1)
> Hmm. I would have said we did, but i don't see it.
> 
> It would not be difficult to perform a global query if the stmt has no basic
> block set.   I would have sworn we did that  :-P
> 
> Maybe we decided it doesn't make sense to pass in a stmt for context that
> isn't in the IL?  there is no context in that case, so passing it in might
> be in error?

Yes, I definitely consider what the vectorizer does here an error.  SCEV
will also blow up, and ranger might ask it?

> I'm OK wither way.. in range_of_expr, something like
> 
>   // If there is no statement, just get the global value.
> -  if (!stmt)
> +  if (!stmt || !gimple_bb (stmt))

but then we pass in 'stmt' as SSA_NAME_DEF_STMT (expr) (we should pass
in the context to query for, not the definition, right?), so this
wouldn't change anything.  Ah, there it is:

  // If there is no statement, just get the global value.
  if (!stmt)
    {
      value_range tmp (TREE_TYPE (expr));
      // If there is no global range for EXPR yet, try to evaluate it.
      // This call sets R to a global range regardless.
      if (!m_cache.get_global_range (r, expr))
        {
          gimple *s = SSA_NAME_DEF_STMT (expr);
          // Calculate a range for S if it is safe to do so.
          if (s && gimple_bb (s) && gimple_get_lhs (s) == expr)
                ^^^^^^^^^^^^^^^^^
            return range_of_stmt (r, s);

and the safety in the if (stmt) case doesn't trigger:

  else
    {
      basic_block bb = gimple_bb (stmt);
      gimple *def_stmt = SSA_NAME_DEF_STMT (expr);

      // If name is defined in this block, try to get an range from S.
      if (def_stmt && gimple_bb (def_stmt) == bb)

because bb is NULL.  I suppose to mimic the above safety check we need
to add && gimple_bb (def_stmt) here as well.

I'll play a bit with this and vectorizer fixes once I got a reduced testcase.

Reply via email to