This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Committed] Reorganize relational operator folding in fold_binary


> 	(fold_div_compare): Fix latent bugs in the previously unreachable
> 	LT_EXPR and GE_EXPR cases.

The change broke the symmetry (L,lo)<->(G,hi) in the code and caused PR 
middle-end/26561.

I think there is confusion over the sign of the overflows.  For example the 
original

    case LT_EXPR:
      if (TREE_OVERFLOW (lo))
	return omit_one_operand (type, integer_zero_node, arg00);
      return fold_build2 (LT_EXPR, type, arg00, lo);

was written for 'lo' overflowing towards -Inf and you've turned it into

    case LT_EXPR:
      if (TREE_OVERFLOW (lo))
	return omit_one_operand (type, integer_one_node, arg00);
      return fold_build2 (LT_EXPR, type, arg00, lo);

which is written for 'lo' overflowing towards +Inf.

Similarly, the original

    case GE_EXPR:
      if (TREE_OVERFLOW (lo))
	return omit_one_operand (type, integer_one_node, arg00);
      return fold_build2 (GE_EXPR, type, arg00, lo);

was written for 'lo' overflowing towards -Inf and you've turned it into

    case GE_EXPR:
      if (TREE_OVERFLOW (lo))
	return omit_one_operand (type, integer_zero_node, arg00);
      return fold_build2 (GE_EXPR, type, arg00, lo);

which is written for 'lo' overflowing towards +Inf.


Testcase attached.

-- 
Eric Botcazou
/* PR middle-end/26561 */

extern void abort(void);

int always_one_1 (int a)
{
  if (a/100 >= -999999999)
    return 1;
  else
    return 0;
}

int always_one_2 (int a)
{
  if (a/100 < -999999999)
    return 0;
  else
    return 1;
}

int main(void)
{
  if (always_one_1 (0) != 1)
    abort ();

  if (always_one_2 (0) != 1)
    abort ();

  return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]