Hello,
> >> On 2/15/07, Christian BRUEL <christian.bruel@st.com> wrote:
> >> >for my curiosity, I just had a quick look at fold-const and it looks
> >> >like 'fold_relational_const' only handle the case were ops are
> >INTEGER_CST
> >> >:
> >>
> >> Look in fold_comparison instead. This is already handled.
> >
> >no it is not (or at least, I cannot find it anywhere, and the
> >transformations do not seem to be performed)?
>
> I thought this one in fold_binary should handle it:
>
> case LT_EXPR:
> case GT_EXPR:
> case LE_EXPR:
> case GE_EXPR:
> tem = fold_comparison (code, type, op0, op1);
> if (tem != NULL_TREE)
> return tem;
>
> /* Transform comparisons of the form X +- C CMP X. */
> if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
> && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
> && ((TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
> && !HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0))))
> || (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
> && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1)))))
> {
> ...
I think this is what Christian claimed, that we handle only the
case x + cst cmp x?
Btw. if you wonder why we do not fold the comparison in his testcase,
the reason is that the code in fold_binary does not handle the case
x cmp x + cst...