About the is_gimple_min_invariant predicate

Eric Botcazou ebotcazou@adacore.com
Wed Jul 4 09:24:00 GMT 2007

Ada bootstrap has been broken by the SCC value numbering patch too (this is PR 
tree-optimization/32589) but this might be due to a latent problem.

In the FRE dump:

RHS &p__name_buffer[1]{lb: 1 sz: 1} + n_32 simplified to 
&p__name_buffer[(<unnamed-signed:32>) MAX_EXPR <D.738_31, 0> + 1]{lb: 1 sz: 
1} has constants 0

and the latter expression is caught by the GIMPLE expression verifier:

error: invalid array index (<unnamed-signed:32>) MAX_EXPR <D.738_31, 0> + 1;

FRE computes the remplacement in simplify_binary_expression:

  /* Make sure result is not a complex expression consiting
     of operators of operators (IE (a + b) + (a + c))
     Otherwise, we will end up with unbounded expressions if
     fold does anything at all.  */
  if (result)
      if (is_gimple_min_invariant (result))
	return result;

The expression

&p__name_buffer[(<unnamed-signed:32>) MAX_EXPR <D.738_31, 0> + 1]

is_gimple_min_invariant because it is TREE_INVARIANT.  TREE_INVARIANT is 
correct because the semantics of Ada for IN parameters guarantees that the 
index is TREE_INVARIANT and p__name_buffer is a global variable.

I'm therefore wondering whether is_gimple_min_invariant should return true for 
this kind of expressions.

/* Return true if T is function invariant.  Or rather a restricted
   form of function invariant.  */

is_gimple_min_invariant (tree t)
  switch (TREE_CODE (t))
    case ADDR_EXPR:
      return TREE_INVARIANT (t);

    case INTEGER_CST:
    case REAL_CST:
    case STRING_CST:
    case COMPLEX_CST:
    case VECTOR_CST:
      return true;

    /* Vector constant constructors are gimple invariant.  */
      if (TREE_TYPE (t) && TREE_CODE (TREE_TYPE (t)) == VECTOR_TYPE)
	return TREE_CONSTANT (t);
	return false;

      return false;

I think that the head comment is a little confusing: is it a formal predicate 
of the GIMPLE grammar, as most of its uses would suggest, e.g.

/* Return true if T is a GIMPLE rvalue, i.e. an identifier or a constant.  */

is_gimple_val (tree t)
  /* Make loads from volatiles and memory vars explicit.  */
  if (is_gimple_variable (t)
      && is_gimple_reg_type (TREE_TYPE (t))
      && !is_gimple_reg (t))
    return false;

  /* FIXME make these decls.  That can happen only when we expose the
     entire landing-pad construct at the tree level.  */
    return true;

  return (is_gimple_variable (t) || is_gimple_min_invariant (t));

or does it have really something to do with TREE_INVARIANT trees?

Eric Botcazou

More information about the Gcc mailing list