[llvm] [NVPTX] Constant fold NVVM fmin and fmax (PR #121966)

Lewis Crawford via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 02:02:04 PST 2025


================
@@ -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)
----------------
LewisCrawford wrote:

Yes, I added the following cases for all the NVVM fmax/fmin intrinsics:

- FMax(1.25, -2.0) 
- FMax(+Subnormal, NaN) 
- FMax(NaN, undef)

- FMin(1.25, -2.0)
- FMin(+Subnormal, NaN)
- FMin(NaN, undef)

In the cases with Subnormal, the FTZ version returns 0.0, and the non-FTZ version returns the unmodified subnormal value 0x380FFFFFC0000000

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


More information about the llvm-commits mailing list