[llvm] [NVPTX] Constant fold NVVM fmin and fmax (PR #121966)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 09:18:41 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-nvptx
Author: Lewis Crawford (LewisCrawford)
<details>
<summary>Changes</summary>
Add constant-folding for nvvm float/double fmin + fmax intrinsics, including all combinations of xorsign.abs, nan-propagation, and ftz.
---
Patch is 30.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/121966.diff
3 Files Affected:
- (modified) llvm/include/llvm/IR/NVVMIntrinsicUtils.h (+49-2)
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+133-1)
- (added) llvm/test/Transforms/InstSimplify/const-fold-nvvm-fmin-fmax.ll (+614)
``````````diff
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicUtils.h b/llvm/include/llvm/IR/NVVMIntrinsicUtils.h
index 8ca073ba822534..d533f944f90ff2 100644
--- a/llvm/include/llvm/IR/NVVMIntrinsicUtils.h
+++ b/llvm/include/llvm/IR/NVVMIntrinsicUtils.h
@@ -38,9 +38,8 @@ enum class TMAReductionOp : uint8_t {
XOR = 7,
};
-inline bool IntrinsicShouldFTZ(Intrinsic::ID IntrinsicID) {
+inline bool FloatToIntIntrinsicShouldFTZ(Intrinsic::ID IntrinsicID) {
switch (IntrinsicID) {
- // Float to i32 / i64 conversion intrinsics:
case Intrinsic::nvvm_f2i_rm_ftz:
case Intrinsic::nvvm_f2i_rn_ftz:
case Intrinsic::nvvm_f2i_rp_ftz:
@@ -171,6 +170,54 @@ IntrinsicGetRoundingMode(Intrinsic::ID IntrinsicID) {
return APFloat::roundingMode::Invalid;
}
+inline bool FMinFMaxShouldFTZ(Intrinsic::ID IntrinsicID) {
+ switch (IntrinsicID) {
+ case Intrinsic::nvvm_fmax_ftz_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_ftz_xorsign_abs_f:
+
+ case Intrinsic::nvvm_fmin_ftz_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_ftz_xorsign_abs_f:
+ return true;
+ }
+ return false;
+}
+
+inline bool FMinFMaxPropagatesNaNs(Intrinsic::ID IntrinsicID) {
+ switch (IntrinsicID) {
+ case Intrinsic::nvvm_fmax_ftz_nan_f:
+ case Intrinsic::nvvm_fmax_nan_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_nan_xorsign_abs_f:
+
+ case Intrinsic::nvvm_fmin_ftz_nan_f:
+ case Intrinsic::nvvm_fmin_nan_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_nan_xorsign_abs_f:
+ return true;
+ }
+ return false;
+}
+
+inline bool FMinFMaxIsXorSignAbs(Intrinsic::ID IntrinsicID) {
+ switch (IntrinsicID) {
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_xorsign_abs_f:
+
+ case Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_xorsign_abs_f:
+ return true;
+ }
+ return false;
+}
+
} // namespace nvvm
} // namespace llvm
#endif // LLVM_IR_NVVMINTRINSICUTILS_H
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 031d675c330ec4..75150ed97aa7b4 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1689,6 +1689,28 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case Intrinsic::x86_avx512_cvttsd2usi64:
return !Call->isStrictFP();
+ // NVVM FMax intrinsics
+ case Intrinsic::nvvm_fmax_d:
+ case Intrinsic::nvvm_fmax_f:
+ case Intrinsic::nvvm_fmax_ftz_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_nan_f:
+ case Intrinsic::nvvm_fmax_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_xorsign_abs_f:
+
+ // NVVM FMin intrinsics
+ case Intrinsic::nvvm_fmin_d:
+ case Intrinsic::nvvm_fmin_f:
+ case Intrinsic::nvvm_fmin_ftz_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_nan_f:
+ case Intrinsic::nvvm_fmin_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_xorsign_abs_f:
+
// NVVM float/double to int32/uint32 conversion intrinsics
case Intrinsic::nvvm_f2i_rm:
case Intrinsic::nvvm_f2i_rn:
@@ -2432,7 +2454,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
return ConstantInt::get(Ty, 0);
APFloat::roundingMode RMode = nvvm::IntrinsicGetRoundingMode(IntrinsicID);
- bool IsFTZ = nvvm::IntrinsicShouldFTZ(IntrinsicID);
+ bool IsFTZ = nvvm::FloatToIntIntrinsicShouldFTZ(IntrinsicID);
bool IsSigned = nvvm::IntrinsicConvertsToSignedInteger(IntrinsicID);
APSInt ResInt(Ty->getIntegerBitWidth(), !IsSigned);
@@ -2892,12 +2914,49 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
case Intrinsic::minnum:
case Intrinsic::maximum:
case Intrinsic::minimum:
+ case Intrinsic::nvvm_fmax_d:
+ case Intrinsic::nvvm_fmin_d:
// If one argument is undef, return the other argument.
if (IsOp0Undef)
return Operands[1];
if (IsOp1Undef)
return Operands[0];
break;
+
+ case Intrinsic::nvvm_fmax_f:
+ case Intrinsic::nvvm_fmax_ftz_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_nan_f:
+ case Intrinsic::nvvm_fmax_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_xorsign_abs_f:
+
+ case Intrinsic::nvvm_fmin_f:
+ case Intrinsic::nvvm_fmin_ftz_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_nan_f:
+ case Intrinsic::nvvm_fmin_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_xorsign_abs_f:
+ // If one arg is undef, the other arg can be returned only if it is
+ // constant, as we may need to flush it to sign-preserving zero or
+ // canonicalize the NaN.
+ if (!IsOp0Undef && !IsOp1Undef)
+ break;
+ if (auto *Op = dyn_cast<ConstantFP>(Operands[IsOp0Undef ? 1 : 0])) {
+ if (Op->isNaN()) {
+ APInt NVCanonicalNaN(32, 0x7fffffff);
+ return ConstantFP::get(
+ Ty, APFloat(Ty->getFltSemantics(), NVCanonicalNaN));
+ }
+ if (nvvm::FMinFMaxShouldFTZ(IntrinsicID))
+ return ConstantFP::get(Ty, FTZPreserveSign(Op->getValueAPF()));
+ else
+ return Op;
+ }
+ break;
}
}
@@ -2955,6 +3014,79 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty,
return ConstantFP::get(Ty->getContext(), minimum(Op1V, Op2V));
case Intrinsic::maximum:
return ConstantFP::get(Ty->getContext(), maximum(Op1V, Op2V));
+
+ case Intrinsic::nvvm_fmax_d:
+ case Intrinsic::nvvm_fmax_f:
+ case Intrinsic::nvvm_fmax_ftz_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_nan_f:
+ case Intrinsic::nvvm_fmax_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_xorsign_abs_f:
+
+ case Intrinsic::nvvm_fmin_d:
+ case Intrinsic::nvvm_fmin_f:
+ case Intrinsic::nvvm_fmin_ftz_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_f:
+ case Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_nan_f:
+ case Intrinsic::nvvm_fmin_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmin_xorsign_abs_f: {
+
+ bool ShouldCanonicalizeNaNs = IntrinsicID != Intrinsic::nvvm_fmax_d &&
+ IntrinsicID != Intrinsic::nvvm_fmin_d;
+ bool IsFTZ = nvvm::FMinFMaxShouldFTZ(IntrinsicID);
+ bool IsNaNPropagating = nvvm::FMinFMaxPropagatesNaNs(IntrinsicID);
+ bool IsXorSignAbs = nvvm::FMinFMaxIsXorSignAbs(IntrinsicID);
+
+ APFloat A = IsFTZ ? FTZPreserveSign(Op1V) : Op1V;
+ APFloat B = IsFTZ ? FTZPreserveSign(Op2V) : Op2V;
+
+ bool XorSign = false;
+ if (IsXorSignAbs) {
+ XorSign = A.isNegative() ^ B.isNegative();
+ A = abs(A);
+ B = abs(B);
+ }
+
+ bool IsFMax = false;
+ switch (IntrinsicID) {
+ case Intrinsic::nvvm_fmax_d:
+ case Intrinsic::nvvm_fmax_f:
+ case Intrinsic::nvvm_fmax_ftz_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_f:
+ case Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_ftz_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_nan_f:
+ case Intrinsic::nvvm_fmax_nan_xorsign_abs_f:
+ case Intrinsic::nvvm_fmax_xorsign_abs_f:
+ IsFMax = true;
+ break;
+ }
+ APFloat Res = IsFMax ? maximum(A, B) : minimum(A, B);
+
+ if (ShouldCanonicalizeNaNs) {
+ APFloat NVCanonicalNaN(Res.getSemantics(), APInt(32, 0x7fffffff));
+ if (A.isNaN() && B.isNaN())
+ return ConstantFP::get(Ty, NVCanonicalNaN);
+ else if (IsNaNPropagating && (A.isNaN() || B.isNaN()))
+ return ConstantFP::get(Ty, NVCanonicalNaN);
+ }
+
+ if (A.isNaN() && B.isNaN())
+ return Operands[1];
+ else if (A.isNaN())
+ Res = B;
+ else if (B.isNaN())
+ Res = A;
+
+ if (IsXorSignAbs && XorSign != Res.isNegative())
+ Res.changeSign();
+
+ return ConstantFP::get(Ty->getContext(), Res);
+ }
}
if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy())
diff --git a/llvm/test/Transforms/InstSimplify/const-fold-nvvm-fmin-fmax.ll b/llvm/test/Transforms/InstSimplify/const-fold-nvvm-fmin-fmax.ll
new file mode 100644
index 00000000000000..ab277483dbba5a
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/const-fold-nvvm-fmin-fmax.ll
@@ -0,0 +1,614 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instsimplify -march=nvptx64 --mcpu=sm_86 --mattr=+ptx72 -S | FileCheck %s
+
+; Check constant-folding for NVVM fmin fmax intrinsics
+
+;###############################################################
+;# FMax(1.25, -2.0) #
+;###############################################################
+
+define double @test_fmax_1_25_neg_2_d() {
+; CHECK-LABEL: define double @test_fmax_1_25_neg_2_d() {
+; CHECK-NEXT: ret double 1.250000e+00
+;
+ %res = call double @llvm.nvvm.fmax.d(double 1.25, double -2.0)
+ ret double %res
+}
+
+define float @test_fmax_1_25_neg_2_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_f() {
+; CHECK-NEXT: ret float 1.250000e+00
+;
+ %res = call float @llvm.nvvm.fmax.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_ftz_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_ftz_f() {
+; CHECK-NEXT: ret float 1.250000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_ftz_nan_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_ftz_nan_f() {
+; CHECK-NEXT: ret float 1.250000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_ftz_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_ftz_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float -2.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.nan.xorsign.abs.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_ftz_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_ftz_xorsign_abs_f() {
+; CHECK-NEXT: ret float -2.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.xorsign.abs.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_nan_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_nan_f() {
+; CHECK-NEXT: ret float 1.250000e+00
+;
+ %res = call float @llvm.nvvm.fmax.nan.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float -2.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.nan.xorsign.abs.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+define float @test_fmax_1_25_neg_2_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_1_25_neg_2_xorsign_abs_f() {
+; CHECK-NEXT: ret float -2.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.xorsign.abs.f(float 1.25, float -2.0)
+ ret float %res
+}
+
+;###############################################################
+;# FMax(+Subnormal, NaN) #
+;###############################################################
+
+define double @test_fmax_pos_subnorm_nan_d() {
+; CHECK-LABEL: define double @test_fmax_pos_subnorm_nan_d() {
+; CHECK-NEXT: ret double 0x380FFFFFC0000000
+;
+ %res = call double @llvm.nvvm.fmax.d(double 0x380FFFFFC0000000, double 0x7fff444400000000)
+ ret double %res
+}
+
+define float @test_fmax_pos_subnorm_nan_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_f() {
+; CHECK-NEXT: ret float 0x380FFFFFC0000000
+;
+ %res = call float @llvm.nvvm.fmax.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_ftz_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_ftz_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_ftz_nan_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_ftz_nan_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_ftz_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_ftz_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.ftz.nan.xorsign.abs.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_ftz_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_ftz_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.xorsign.abs.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_nan_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_nan_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.nan.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.nan.xorsign.abs.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+define float @test_fmax_pos_subnorm_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_pos_subnorm_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x380FFFFFC0000000
+;
+ %res = call float @llvm.nvvm.fmax.xorsign.abs.f(float 0x380FFFFFC0000000, float 0x7fff444400000000)
+ ret float %res
+}
+
+;###############################################################
+;# FMax(subnorm, undef) #
+;###############################################################
+
+define double @test_fmax_subnorm_undef_d() {
+; CHECK-LABEL: define double @test_fmax_subnorm_undef_d() {
+; CHECK-NEXT: ret double 0x380FFFFFC0000000
+;
+ %res = call double @llvm.nvvm.fmax.d(double 0x380FFFFFC0000000, double undef)
+ ret double %res
+}
+
+define float @test_fmax_subnorm_undef_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_f() {
+; CHECK-NEXT: ret float 0x380FFFFFC0000000
+;
+ %res = call float @llvm.nvvm.fmax.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_ftz_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_ftz_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_ftz_nan_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_ftz_nan_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_ftz_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_ftz_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.nan.xorsign.abs.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_ftz_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_ftz_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0.000000e+00
+;
+ %res = call float @llvm.nvvm.fmax.ftz.xorsign.abs.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_nan_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_nan_f() {
+; CHECK-NEXT: ret float 0x380FFFFFC0000000
+;
+ %res = call float @llvm.nvvm.fmax.nan.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x380FFFFFC0000000
+;
+ %res = call float @llvm.nvvm.fmax.nan.xorsign.abs.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_subnorm_undef_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_subnorm_undef_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x380FFFFFC0000000
+;
+ %res = call float @llvm.nvvm.fmax.xorsign.abs.f(float 0x380FFFFFC0000000, float undef)
+ ret float %res
+}
+
+;###############################################################
+;# FMax(NaN, undef) #
+;###############################################################
+; Ensure we canonicalize the NaNs for f32
+
+define double @test_fmax_nan_undef_d() {
+; CHECK-LABEL: define double @test_fmax_nan_undef_d() {
+; CHECK-NEXT: ret double 0x7FF4444400000000
+;
+ %res = call double @llvm.nvvm.fmax.d(double 0x7ff4444400000000, double undef)
+ ret double %res
+}
+
+define float @test_fmax_nan_undef_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_ftz_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_ftz_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_ftz_nan_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_ftz_nan_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.ftz.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_ftz_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_ftz_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.ftz.nan.xorsign.abs.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_ftz_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_ftz_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.ftz.xorsign.abs.f(float 0x7ffff4ff00000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_nan_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_nan_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.nan.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_nan_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_nan_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.nan.xorsign.abs.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+define float @test_fmax_nan_undef_xorsign_abs_f() {
+; CHECK-LABEL: define float @test_fmax_nan_undef_xorsign_abs_f() {
+; CHECK-NEXT: ret float 0x7FFFFFFFE0000000
+;
+ %res = call float @llvm.nvvm.fmax.xorsign.abs.f(float 0x7fff444400000000, float undef)
+ ret float %res
+}
+
+;############...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/121966
More information about the llvm-commits
mailing list