[llvm] [NVPTX] Fix NaN + overflow semantics of f2ll/d2i (PR #159530)
Durgadoss R via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 11:08:38 PDT 2025
================
@@ -281,21 +281,12 @@ static Instruction *convertNvvmIntrinsicToLlvm(InstCombiner &IC,
return {Intrinsic::trunc, FTZ_MustBeOn};
// NVVM intrinsics that map to LLVM cast operations.
- //
- // Note that llvm's target-generic conversion operators correspond to the rz
- // (round to zero) versions of the nvvm conversion intrinsics, even though
- // most everything else here uses the rn (round to nearest even) nvvm ops.
- case Intrinsic::nvvm_d2i_rz:
- case Intrinsic::nvvm_f2i_rz:
- case Intrinsic::nvvm_d2ll_rz:
- case Intrinsic::nvvm_f2ll_rz:
- return {Instruction::FPToSI};
- case Intrinsic::nvvm_d2ui_rz:
- case Intrinsic::nvvm_f2ui_rz:
- case Intrinsic::nvvm_d2ull_rz:
- case Intrinsic::nvvm_f2ull_rz:
- return {Instruction::FPToUI};
- // Integer to floating-point uses RN rounding, not RZ
+ // Note - we cannot map intrinsics like nvvm_d2ll_rz to LLVM's
+ // FPToSI, as NaN to int conversion with FPToSI is considered UB and is
+ // eliminated. NVVM conversion intrinsics are translated to PTX cvt
+ // instructions which define the outcome for NaN rather than leaving as UB.
+ // Therefore, translate NVVM intrinsics to sitofp/uitofp, but not to
+ // fptosi/fptoui.
----------------
durga4github wrote:
Thanks for this comment!
https://github.com/llvm/llvm-project/pull/159530
More information about the llvm-commits
mailing list