[tree-ssa/mainline PATCH] fold "test"==0 into constant

Jan Hubicka hubicka@ucw.cz
Thu Nov 6 17:09:00 GMT 2003


> > > +     case MAX_EXPR:
> > > +       if (tree_expr_nonzero_p (TREE_OPERAND (t, 0)))
> > > + 	{
> > > + 	  if (tree_expr_nonzero_p (TREE_OPERAND (t, 1)))
> > > + 	    return true;
> > > + 	  return (tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
> > > + 	          && tree_expr_nonnegative_p (TREE_OPERAND (t, 1)));
> > > + 	}
> > > +       else if (tree_expr_nonzero_p (TREE_OPERAND (t, 1)))
> > > + 	{
> > > + 	  if (tree_expr_nonzero_p (TREE_OPERAND (t, 0)))
> > > + 	    return true;
> > > + 	  return (tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
> > > + 	          && tree_expr_nonnegative_p (TREE_OPERAND (t, 1)));
> > > + 	}
> > > +       break;
> > 
> > For example, here I can't work out what you're trying to do.  Clearly
> > there's plenty of redundancy and unreachable clauses.  For the time
> > being you might consider the same implementation as MIN_EXPR whilst
> > you give the problem some thought.
> 
> I am testing that either both operands are nonzero, or one of them is
> nonzero and both are positive.  What clause in unreahcable?

OK, adding comments helped at least to catch my confusion :)
Now the critical tests looks like:

    case PLUS_EXPR:
      if (!TREE_UNSIGNED (type) && !flag_wrapv)
	{
	  /* With the presence of negative values it is hard
	     to say something.  */
	  if (!tree_expr_nonnegative_p (TREE_OPERAND (t, 0))
	      || !tree_expr_nonnegative_p (TREE_OPERAND (t, 1)))
	    return false;
	  /* One of operands must be positive and the other nonnegative.  */
	  return (tree_expr_nonzero_p (TREE_OPERAND (t, 0))
	          || tree_expr_nonzero_p (TREE_OPERAND (t, 1)));
	}
      break;

    case MAX_EXPR:
      if (tree_expr_nonzero_p (TREE_OPERAND (t, 0)))
	{
	  /* When both operands are nonzero, then MAX must be too.  */
	  if (tree_expr_nonzero_p (TREE_OPERAND (t, 1)))
	    return true;

	  /* MAX where operand 0 is positive is positive.  */
	  return tree_expr_nonnegative_p (TREE_OPERAND (t, 0));
	}
      /* MAX where operand 1 is positive is positive.  */
      else if (tree_expr_nonzero_p (TREE_OPERAND (t, 1))
	       && tree_expr_nonnegative_p (TREE_OPERAND (t, 1)))
	return true;
      break;
Does it look understandable now or should I go for backup plan?  (there
is at least one call now that would fold into positive_p predicate).
Sorry for me being so dense today.  I will take break now.

Honza



More information about the Gcc-patches mailing list