Richard Sandiford <[email protected]> writes:
>>> I'd actually considered converting to signed and back instead of adding
>>> extra cases, but I thought that would be rejected as too inefficient.
>>> (That was a concern with my patch above.) It seemed like one of the selling
>>> points of doing it your way was that everything was handled by one switch
>>> statement "in" and one switch statement "out", and I was trying to
>>> preserve that.
>>>
>>> signed_condition and unsigned_condition assert on unordered comparisons,
>>> so if we're going to go that route, we either need to filter them out
>>> first or add maybe_* versions of the routines that return UNKNOWN.
>>
>> Yeah. rs6000 has
>>
>> (define_predicate "unsigned_comparison_operator"
>> (match_code "ltu,gtu,leu,geu"))
>> (define_predicate "signed_comparison_operator"
>> (match_code "lt,gt,le,ge"))
>>
>> Maybe we should have those be for every target?
>>
>> bool is_signed = (signed_comparison_operator (code0)
>> || signed_comparison_operator (code1));
>> bool is_unsigned = (unsigned_comparison_operator (code0)
>> || unsigned_comparison_operator (code1));
>>
>> /* Don't allow mixing signed and unsigned comparisons. */
>> if (is_signed && is_unsigned)
>> return 0;
>>
>> (this takes care of your EQ/NE concern automatically, btw)
>>
>> if (unsigned_comparison_operator (code0))
>> code0 = signed_condition (code0);
>> if (unsigned_comparison_operator (code1))
>> code1 = signed_condition (code1);
>>
>> and at the end
>>
>> if (is_unsigned && signed_comparison_operator (code))
>> code = unsigned_condition (code);
>
> OK, thanks, I'll do it this way.
Actually, this doesn't work because *_operators want rtxes rather
than codes. I can get around that by passing op0 and op1 for
the existing rtxes. For the conversion at the end, I can do:
machine_mode compared_mode = GET_MODE (XEXP (op0, 0));
if (code == ORDERED && INTEGRAL_MODE_P (compared_mode))
return const_true_rtx;
if (is_unsigned)
code = unsigned_condition (code);
Or I can add signed_comparison_p and unsigned_comparison_p functions
that take codes instead of rtxes.
Do either of those sound OK, or would you prefer something else?
Richard