[PATCH] reorganize simplify_const_relational_operation
Eric Botcazou
ebotcazou@libertysurf.fr
Wed Sep 19 11:09:00 GMT 2007
> Actually I think that the sign-extension is useless, only the l0u and
> l1u zero-extension does something.
Yes, I agree, constants are now sign-extended for their "mode" and the code in
simplify_const_relational_operation predates this invariant. But then it's
also useless to recompute h0s and h1s, so we would end up with
/* If WIDTH is nonzero and not greater than HOST_BITS_PER_WIDE_INT,
we have to zero-extend the unsigned values. */
if (width != 0 && width <= HOST_BITS_PER_WIDE_INT)
{
if (width < HOST_BITS_PER_WIDE_INT)
{
l0u &= ((HOST_WIDE_INT) 1 << width) - 1;
l1u &= ((HOST_WIDE_INT) 1 << width) - 1;
}
h0u = 0;
h1u = 0;
}
But the 4 variables are unsigned HOST_WIDE_INT and the zeroed bits are a copy
of the most significant non-zeroed bit, so what's the point in zeroing them?
In other words, can't we simply rewrite the code into something like
HOST_WIDE_INT high0, high1;
unsigned HOST_WIDE_INT low0, low1;
int cr;
if (GET_CODE (trueop0) == CONST_DOUBLE)
{
low0 = CONST_DOUBLE_LOW (trueop0);
high0 = CONST_DOUBLE_HIGH (trueop0);
}
else
{
low0 = INTVAL (trueop0);
high0 = HWI_SIGN_EXTEND (low0);
}
if (GET_CODE (trueop1) == CONST_DOUBLE)
{
low1 = CONST_DOUBLE_LOW (trueop1);
high1 = CONST_DOUBLE_HIGH (trueop1);
}
else
{
low1 = INTVAL (trueop1);
high1 = HWI_SIGN_EXTEND (low1);
}
if (high0 == high1 && low0 == low1)
cr = EQ;
else
{
cr = (high0 < high1 || (high0 == high1 && low0 < low1)) ? CR_LT : CR_GT;
cr |= ((unsigned HOST_WIDE_INT)high0 < (unsigned HOST_WIDE_INT)high1
|| (high0 == high1 && low0 < low1)) ? CR_LTU : CR_GTU;
}
return comparison_result (code, cr);
assuming that the constants we get are correct for their "mode"?
Btw, it looks like simplify_const_relational_operation can be made static.
--
Eric Botcazou
More information about the Gcc-patches
mailing list