Proposal for adding rounding variant of fpto?i instructions

Hi Peter,

I would appreciate comments/feedback on this proposal to extend the
fpto?i instructions to support rounding.

I think this might be useful. Actually, LLVM specifies that fpto?i convert
their operand into the nearest (rounding towards zero) signed integer value.
Do you have other rounding modes in mind? Currently I use custom metadata to
represent conversions with other rounding modes.

Best, Anton.

Hi Anton,

I wanted to stick to round-to-zero (as we have now) plus the current
FPU rounding mode. We could add other rounding modes, but I don't
think it would be sensible to do this for fpto?i alone without also
affecting the other FP operations in a similar way. That would be a
project that would go far beyond my current needs, especially since
most architectures do not have a way to specify the rounding mode in
the instruction (requiring, I would imagine, an legalisation pass and
a new set of intrinsics and/or SelectionDAG nodes for manipulating
the rounding mode).

OTOH, fpto?i with current rounding mode seemed to be supported on
approx half of the architectures I surveyed, and would bring fpto?i
in line (operation-wise) with the other FP operations, which makes
a more compelling argument for this being (initially) supported as
an instruction.

In terms of adding other rounding modes, the proposed design is
extensible in that the immediate argument to FP_TO_?INT in the
SelectionDAG can be used in the future to indicate an arbitrary
rounding mode (or a special value meaning "current rounding mode").
The same format rounding mode argument can also be added to other
FP operations.

Thanks,