[LLVMdev] Proposal for adding rounding variant of fpto?i instructions
peter at pcc.me.uk
Mon Jun 28 14:44:10 PDT 2010
I would appreciate comments/feedback on this proposal to extend the
fpto?i instructions to support rounding. This is my first proposed
significant extension to LLVM so I'd like to know if I'm completely
off base here.
First of all, I noticed the convert* intrinsics corresponding to the
CONVERT_RNDSAT InstructionDAG. I propose not to build my work on
top of these as they seem to be temporary. Dan Gohman on IRC let me
know these are used by a closed source OpenCL backend, and I imagine
that at some stage the OpenCL backend could migrate to the standard
This is what I propose:
Add a "round" flag to FPToUIInst and FPToSIInst. The absence of this
flag means truncation is needed whereas presence indicates rounding.
The SelectionDAG for FP_TO_UINT and FP_TO_SINT are extended to add
an immediate that indicates whether rounding is needed.
To legalise a rounding FP_TO_UINT or FP_TO_SINT we use the technique
described in  to convert the operation into an add/bitcast.
Please let me know what you think.
More information about the llvm-dev