This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Committed] Reorganize relational operator folding in fold_binary
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 6 Mar 2006 10:10:09 +0100
- Subject: Re: [Committed] Reorganize relational operator folding in fold_binary
- References: <Pine.LNX.4.44.0602241127150.338-100000@www.eyesopen.com>
> (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;
}