[llvm] [ConstantFolding] Fix incorrect nvvm_round folding (PR #151563)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 11:49:49 PDT 2025


================
@@ -2679,11 +2679,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
       case Intrinsic::nvvm_round_ftz_f:
       case Intrinsic::nvvm_round_f:
       case Intrinsic::nvvm_round_d: {
-        // Use APFloat implementation instead of native libm call, as some
-        // implementations (e.g. on PPC) do not preserve the sign of negative 0.
         bool IsFTZ = nvvm::UnaryMathIntrinsicShouldFTZ(IntrinsicID);
         auto V = IsFTZ ? FTZPreserveSign(APF) : APF;
-        V.roundToIntegral(APFloat::rmNearestTiesToAway);
+        V.roundToIntegral(APFloat::rmNearestTiesToEven);
----------------
Artem-B wrote:

I'd add a comment that the intrinsic is lowered to an `cvt.rni` instruction variant, which
> .rni - round to nearest integer, choosing even integer if source is equidistant between two integers

https://github.com/llvm/llvm-project/pull/151563


More information about the llvm-commits mailing list