[PATCH] D142093: [InstCombine] trunc (fptoui|fptosi)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 05:07:25 PST 2023


spatel added a comment.

In D142093#4068247 <https://reviews.llvm.org/D142093#4068247>, @samparker wrote:

>> it should be sufficient to have the intermediate integer width be one more than the minimum required type width, so "%i = fptoui half %x to i17".
>
> IIUC, for half fptoui we don't need an i17, as an i16 can hold the max normal value (65504). I can add support in for float conversions though, as this logic is only triggering for simple types, I assume the only conversion that will work is float -> i128 -> i64.

i16 is the smallest final type for fptoui; i17 is one bit bigger because we need to truncate at least one bit. We don't really want a "simple type" limit here in IR either unless there's some codegen concern. I'd add tests with float and bfloat. There's a current discussion about adding various other small format FP types to IR, so we should try to future-proof this transform for those types in case they make it into IR.

> I would really appreciate if someone could help me understand the complication with fptosi w.r.t checking for poison/undef too.

There is no undef problem - I think it's just that the online instance times out with larger widths:
https://alive2.llvm.org/ce/z/6EZXLQ


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142093/new/

https://reviews.llvm.org/D142093



More information about the llvm-commits mailing list