[PATCH] D53794: [TargetLowering] expandFP_TO_UINT - avoid FPE due to out of range conversion (PR17686)

Kevin P. Neal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 19 07:57:47 PST 2018


kpn added a comment.

In https://reviews.llvm.org/D53794#1302746, @uweigand wrote:

> As I understand the approach, it can never **introduce** a new trap.  Now of course, if the original source value is outside the range of the target integer type, some of the instructions introduced by this approach may trap, but in that case, it is expected for the fp_to_uint operation to trap somewhere.
>
> If the original source value is in range however, then none of the instructions introduced here can ever trap:
>
>   	​    // Sel = Src < 0x8000000000000000
>   	​    // Val = select Sel, Src, Src - 0x8000000000000000
>   	​    // Ofs = select Sel, 0, 0x8000000000000000
>   	​    // Result = fp_to_sint(Val) ^ Ofs
>  
>
>
> The first is a compare that never traps.  The select operations themselves also never trap.  The first select in addition contains a subtraction, but if Src is in range for the fp_to_uint operation, that subtract cannot trap either. Finally, if Src is in range for fp_to_uint, then by construction the value Val will be in range for fp_to_sint, and therefore that operation cannot trap either.


OK, thanks for the clarification. That makes sense.

I like that this isn't a pass and therefore doesn't cost us any compilation time when it isn't needed.


Repository:
  rL LLVM

https://reviews.llvm.org/D53794





More information about the llvm-commits mailing list