[llvm] [InstCombine][ValueTracking] Add m_FMinNum and m_FMaxNum to matchFastFloatClamp. (PR #188149)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 09:13:27 PDT 2026


================
@@ -590,3 +590,67 @@ define <2 x float> @mixed_clamp_to_float_vec(<2 x i32> %x) {
   %r = select <2 x i1> %lo_cmp, <2 x float> <float 1.0, float 1.0>, <2 x float> %f_min
   ret <2 x float> %r
 }
+
+define i8 @clamp_float_fast_minmax_select_nsz_fptoui(float %x) {
+; CHECK-LABEL: @clamp_float_fast_minmax_select_nsz_fptoui(
+; CHECK-NEXT:    [[MIN:%.*]] = call nnan nsz float @llvm.minnum.f32(float [[X:%.*]], float 2.550000e+02)
+; CHECK-NEXT:    [[R:%.*]] = call nnan nsz float @llvm.maxnum.f32(float [[MIN]], float 0.000000e+00)
+; CHECK-NEXT:    [[FPTOUI:%.*]] = fptoui float [[R]] to i8
+; CHECK-NEXT:    ret i8 [[FPTOUI]]
+;
+  %cmp2 = fcmp nnan ogt float %x, 255.0
+  %min = select nsz i1 %cmp2, float 255.0, float %x
+  %cmp1 = fcmp nnan olt float %x, 0.0
+  %r = select nsz i1 %cmp1, float 0.0, float %min
----------------
topperc wrote:

Prior to this patch, the first 2 instructions get converted to minnum/maxnum, but the last 2 instructions don't. With this patch they do. Do you want me to make the first 2 instruction minnum/maxnum to only test the code that's in the patch?

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


More information about the llvm-commits mailing list