https://github.com/VedantParanjape updated 
https://github.com/llvm/llvm-project/pull/159652

>From c179dfaf6064ec8018c1c12aa7657858e573e57f Mon Sep 17 00:00:00 2001
From: Vedant Paranjape <vedantparanjape160...@gmail.com>
Date: Tue, 16 Sep 2025 04:17:22 -0400
Subject: [PATCH 1/3] [InstCombine] fold float clamp pattern into llvm.max/min

%v0 = fcmp nsz ogt float %arg0, 0.000000e+00
%v1 = select nsz i1 %v0, float %arg0, float 0.000000e+00
====
%v0 = call float @llvm.maxnum.f32(float %arg0, float 0.000000e+00[)
====

fcmp + select patterns can be folded into fmax/fmin. This patch handles
this transformation for OGT and OLT.

Fixes #157486
---
 .../InstCombine/InstCombineSelect.cpp         | 57 +++++++++++++++++
 .../Transforms/InstCombine/clamp-to-minmax.ll | 64 +++++++------------
 .../Transforms/InstCombine/fcmp-select.ll     |  9 +--
 llvm/test/Transforms/InstCombine/fptrunc.ll   |  5 +-
 .../InstCombine/load-bitcast-select.ll        |  6 +-
 .../InstCombine/loadstore-metadata.ll         | 15 ++---
 .../Transforms/InstCombine/minmax-fold.ll     |  6 +-
 llvm/test/Transforms/InstCombine/minmax-fp.ll | 33 ++++------
 .../multiple-uses-load-bitcast-select.ll      |  6 +-
 .../Transforms/InstCombine/select-select.ll   |  9 +--
 .../InstCombine/simplify-demanded-fpclass.ll  | 15 ++---
 .../InstCombine/unordered-fcmp-select.ll      |  6 +-
 .../X86/preserve-access-group.ll              | 14 ++--
 .../PhaseOrdering/simplifycfg-options.ll      |  3 +-
 14 files changed, 126 insertions(+), 122 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 8f9d0bf6240d5..028a432cdba44 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3963,6 +3963,60 @@ static Value *foldSelectIntoAddConstant(SelectInst &SI,
   return nullptr;
 }
 
+// fcmp + sel patterns into max/min intrinsic.
+static Value *foldSelectICmpIntoMaxMin(SelectInst &SI,
+                                       InstCombiner::BuilderTy &Builder) {
+
+  auto TryFoldIntoMaxMinIntrinsic =
+      [&Builder, &SI](CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS,
+                      Value *TVal, Value *FVal) -> Value * {
+    // Early exit if the operands are not in the expected form.
+    if ((CmpRHS != TVal || CmpLHS != FVal) &&
+        (CmpLHS != TVal || CmpRHS != FVal))
+      return nullptr;
+
+    bool isSwapped = (CmpLHS == FVal && CmpRHS == TVal);
+    // Only these relational predicates can be transformed into maxnum/minnum
+    // intrinsic.
+    // X > C ? X : C --> maxnum(X, C)
+    // X > C ? C : X --> minnum(X, C)
+    if (Pred == CmpInst::FCMP_OGT) {
+      Intrinsic::ID MaxMinIID =
+          isSwapped ? Intrinsic::minnum : Intrinsic::maxnum;
+      return Builder.CreateIntrinsic(SI.getType(), MaxMinIID, {TVal, FVal},
+                                     &SI);
+    }
+
+    // X < C ? X : C --> minnum(X, C)
+    // X < C ? C : X --> maxnum(X, C)
+    if (Pred == CmpInst::FCMP_OLT) {
+      Intrinsic::ID MaxMinIID =
+          isSwapped ? Intrinsic::maxnum : Intrinsic::minnum;
+      return Builder.CreateIntrinsic(SI.getType(), MaxMinIID, {TVal, FVal},
+                                     &SI);
+    }
+
+    return nullptr;
+  };
+
+  // select((fcmp Pred, X, Y), X, Y)
+  //      => minnum/maxnum(X, Y)
+  //
+  // Pred := OGT and OLT
+  Value *X, *Y;
+  Value *TVal, *FVal;
+  CmpPredicate Pred;
+
+  // Note: OneUse check for `Cmp` is necessary because it makes sure that other
+  // InstCombine folds don't undo this transformation and cause an infinite
+  // loop. Furthermore, it could also increase the operation count.
+  if (match(&SI, m_OneUse(m_Select(m_OneUse(m_FCmp(Pred, m_Value(X), 
m_Value(Y))),
+                          m_Value(TVal), m_Value(FVal)))))
+    return TryFoldIntoMaxMinIntrinsic(Pred, X, Y, TVal, FVal);
+
+  return nullptr;
+}
+
 static Value *foldSelectBitTest(SelectInst &Sel, Value *CondVal, Value 
*TrueVal,
                                 Value *FalseVal,
                                 InstCombiner::BuilderTy &Builder,
@@ -4455,6 +4509,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst 
&SI) {
   if (Value *V = foldSelectIntoAddConstant(SI, Builder))
     return replaceInstUsesWith(SI, V);
 
+  if (Value *V = foldSelectICmpIntoMaxMin(SI, Builder))
+    return replaceInstUsesWith(SI, V);
+
   // select(mask, mload(,,mask,0), 0) -> mload(,,mask,0)
   // Load inst is intentionally not checked for hasOneUse()
   if (match(FalseVal, m_Zero()) &&
diff --git a/llvm/test/Transforms/InstCombine/clamp-to-minmax.ll 
b/llvm/test/Transforms/InstCombine/clamp-to-minmax.ll
index 7f3276608c5da..9d33a7835af8a 100644
--- a/llvm/test/Transforms/InstCombine/clamp-to-minmax.ll
+++ b/llvm/test/Transforms/InstCombine/clamp-to-minmax.ll
@@ -5,10 +5,9 @@
 ; (X < C1) ? C1 : MIN(X, C2)
 define float @clamp_float_fast_ordered_strict_maxmin(float %x) {
 ; CHECK-LABEL: @clamp_float_fast_ordered_strict_maxmin(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
-; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+00
-; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MIN]], 
float 1.000000e+00
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
+; CHECK-NEXT:    [[CMP1:%.*]] = fcmp fast olt float [[X]], 1.000000e+00
+; CHECK-NEXT:    [[R1:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R1]]
 ;
   %cmp2 = fcmp fast olt float %x, 255.0
@@ -21,10 +20,9 @@ define float @clamp_float_fast_ordered_strict_maxmin(float 
%x) {
 ; (X <= C1) ? C1 : MIN(X, C2)
 define float @clamp_float_fast_ordered_nonstrict_maxmin(float %x) {
 ; CHECK-LABEL: @clamp_float_fast_ordered_nonstrict_maxmin(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
-; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast oge float [[MIN]], 1.000000e+00
-; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MIN]], 
float 1.000000e+00
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
+; CHECK-NEXT:    [[CMP1:%.*]] = fcmp fast ole float [[X]], 1.000000e+00
+; CHECK-NEXT:    [[R1:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R1]]
 ;
   %cmp2 = fcmp fast olt float %x, 255.0
@@ -37,10 +35,9 @@ define float 
@clamp_float_fast_ordered_nonstrict_maxmin(float %x) {
 ; (X > C1) ? C1 : MAX(X, C2)
 define float @clamp_float_fast_ordered_strict_minmax(float %x) {
 ; CHECK-LABEL: @clamp_float_fast_ordered_strict_minmax(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 
1.000000e+00
-; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02
-; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MAX]], 
float 2.550000e+02
+; CHECK-NEXT:    [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], 
float 1.000000e+00)
+; CHECK-NEXT:    [[CMP1:%.*]] = fcmp fast ogt float [[X]], 2.550000e+02
+; CHECK-NEXT:    [[R1:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float 
[[MAX]]
 ; CHECK-NEXT:    ret float [[R1]]
 ;
   %cmp2 = fcmp fast ogt float %x, 1.0
@@ -53,10 +50,9 @@ define float @clamp_float_fast_ordered_strict_minmax(float 
%x) {
 ; (X >= C1) ? C1 : MAX(X, C2)
 define float @clamp_float_fast_ordered_nonstrict_minmax(float %x) {
 ; CHECK-LABEL: @clamp_float_fast_ordered_nonstrict_minmax(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast ogt float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 
1.000000e+00
-; CHECK-NEXT:    [[DOTINV:%.*]] = fcmp fast ole float [[MAX]], 2.550000e+02
-; CHECK-NEXT:    [[R1:%.*]] = select nnan ninf i1 [[DOTINV]], float [[MAX]], 
float 2.550000e+02
+; CHECK-NEXT:    [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], 
float 1.000000e+00)
+; CHECK-NEXT:    [[CMP1:%.*]] = fcmp fast oge float [[X]], 2.550000e+02
+; CHECK-NEXT:    [[R1:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float 
[[MAX]]
 ; CHECK-NEXT:    ret float [[R1]]
 ;
   %cmp2 = fcmp fast ogt float %x, 1.0
@@ -191,8 +187,7 @@ define float @clamp_negative_same_op(float %x) {
 ; First, check that we don't do bad things in the presence of signed zeros
 define float @clamp_float_with_zero1(float %x) {
 ; CHECK-LABEL: @clamp_float_with_zero1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ole float [[X]], 0.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -206,8 +201,7 @@ define float @clamp_float_with_zero1(float %x) {
 
 define float @clamp_float_with_zero2(float %x) {
 ; CHECK-LABEL: @clamp_float_with_zero2(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp fast olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[X]], 0.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 0.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -228,8 +222,7 @@ define float @clamp_float_with_zero2(float %x) {
 ; (X < C1) ? C1 : MIN(X, C2)
 define float @clamp_float_ordered_strict_maxmin1(float %x) {
 ; CHECK-LABEL: @clamp_float_ordered_strict_maxmin1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[X]], 1.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -259,8 +252,7 @@ define float @clamp_float_ordered_strict_maxmin2(float %x) {
 ; (X <= C1) ? C1 : MIN(X, C2)
 define float @clamp_float_ordered_nonstrict_maxmin1(float %x) {
 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_maxmin1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ole float [[X]], 1.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -290,8 +282,7 @@ define float @clamp_float_ordered_nonstrict_maxmin2(float 
%x) {
 ; (X > C1) ? C1 : MAX(X, C2)
 define float @clamp_float_ordered_strict_minmax1(float %x) {
 ; CHECK-LABEL: @clamp_float_ordered_strict_minmax1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 
1.000000e+00
+; CHECK-NEXT:    [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], 
float 1.000000e+00)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ogt float [[X]], 2.550000e+02
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float 
[[MAX]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -321,8 +312,7 @@ define float @clamp_float_ordered_strict_minmax2(float %x) {
 ; (X >= C1) ? C1 : MAX(X, C2)
 define float @clamp_float_ordered_nonstrict_minmax1(float %x) {
 ; CHECK-LABEL: @clamp_float_ordered_nonstrict_minmax1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 
1.000000e+00
+; CHECK-NEXT:    [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], 
float 1.000000e+00)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp oge float [[X]], 2.550000e+02
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float 
[[MAX]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -355,8 +345,7 @@ define float @clamp_float_ordered_nonstrict_minmax2(float 
%x) {
 ; (X < C1) ? C1 : MIN(X, C2)
 define float @clamp_float_unordered_strict_maxmin1(float %x) {
 ; CHECK-LABEL: @clamp_float_unordered_strict_maxmin1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ult float [[X]], 1.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -386,8 +375,7 @@ define float @clamp_float_unordered_strict_maxmin2(float 
%x) {
 ; (X <= C1) ? C1 : MIN(X, C2)
 define float @clamp_float_unordered_nonstrict_maxmin1(float %x) {
 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_maxmin1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[MIN:%.*]] = select i1 [[CMP2]], float [[X]], float 
2.550000e+02
+; CHECK-NEXT:    [[MIN:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 2.550000e+02)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ule float [[X]], 1.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 1.000000e+00, float 
[[MIN]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -417,8 +405,7 @@ define float @clamp_float_unordered_nonstrict_maxmin2(float 
%x) {
 ; (X > C1) ? C1 : MAX(X, C2)
 define float @clamp_float_unordered_strict_minmax1(float %x) {
 ; CHECK-LABEL: @clamp_float_unordered_strict_minmax1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 
1.000000e+00
+; CHECK-NEXT:    [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], 
float 1.000000e+00)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ugt float [[X]], 2.550000e+02
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float 
[[MAX]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -448,8 +435,7 @@ define float @clamp_float_unordered_strict_minmax2(float 
%x) {
 ; (X >= C1) ? C1 : MAX(X, C2)
 define float @clamp_float_unordered_nonstrict_minmax1(float %x) {
 ; CHECK-LABEL: @clamp_float_unordered_nonstrict_minmax1(
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp ogt float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[MAX:%.*]] = select i1 [[CMP2]], float [[X]], float 
1.000000e+00
+; CHECK-NEXT:    [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], 
float 1.000000e+00)
 ; CHECK-NEXT:    [[CMP1:%.*]] = fcmp uge float [[X]], 2.550000e+02
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[CMP1]], float 2.550000e+02, float 
[[MAX]]
 ; CHECK-NEXT:    ret float [[R]]
@@ -527,8 +513,7 @@ define float @mixed_clamp_to_float_1(i32 %x) {
 
 define i32 @mixed_clamp_to_i32_1(float %x) {
 ; CHECK-LABEL: @mixed_clamp_to_i32_1(
-; CHECK-NEXT:    [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 
2.550000e+02, float [[X]]
+; CHECK-NEXT:    [[FLOAT_MIN:%.*]] = call float @llvm.minnum.f32(float 
[[X:%.*]], float 2.550000e+02)
 ; CHECK-NEXT:    [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32
 ; CHECK-NEXT:    [[I32_X:%.*]] = fptosi float [[X]] to i32
 ; CHECK-NEXT:    [[LO_CMP:%.*]] = icmp eq i32 [[I32_X]], 0
@@ -561,8 +546,7 @@ define float @mixed_clamp_to_float_2(i32 %x) {
 
 define i32 @mixed_clamp_to_i32_2(float %x) {
 ; CHECK-LABEL: @mixed_clamp_to_i32_2(
-; CHECK-NEXT:    [[FLOAT_MIN_CMP:%.*]] = fcmp ogt float [[X:%.*]], 2.550000e+02
-; CHECK-NEXT:    [[FLOAT_MIN:%.*]] = select i1 [[FLOAT_MIN_CMP]], float 
2.550000e+02, float [[X]]
+; CHECK-NEXT:    [[FLOAT_MIN:%.*]] = call float @llvm.minnum.f32(float 
[[X:%.*]], float 2.550000e+02)
 ; CHECK-NEXT:    [[I32_MIN:%.*]] = fptosi float [[FLOAT_MIN]] to i32
 ; CHECK-NEXT:    [[LO_CMP:%.*]] = fcmp olt float [[X]], 1.000000e+00
 ; CHECK-NEXT:    [[R:%.*]] = select i1 [[LO_CMP]], i32 1, i32 [[I32_MIN]]
diff --git a/llvm/test/Transforms/InstCombine/fcmp-select.ll 
b/llvm/test/Transforms/InstCombine/fcmp-select.ll
index b622c8636eccb..63e72fed55350 100644
--- a/llvm/test/Transforms/InstCombine/fcmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp-select.ll
@@ -202,10 +202,8 @@ define <2 x i1> @test_fcmp_select_const_const_vec(<2 x 
double> %x) {
 
 define double @test_fcmp_select_clamp(double %x) {
 ; CHECK-LABEL: @test_fcmp_select_clamp(
-; CHECK-NEXT:    [[CMP1:%.*]] = fcmp ogt double [[X:%.*]], 9.000000e-01
-; CHECK-NEXT:    [[SEL1:%.*]] = select i1 [[CMP1]], double 9.000000e-01, 
double [[X]]
-; CHECK-NEXT:    [[CMP2:%.*]] = fcmp olt double [[SEL1]], 5.000000e-01
-; CHECK-NEXT:    [[SEL2:%.*]] = select i1 [[CMP2]], double 5.000000e-01, 
double [[SEL1]]
+; CHECK-NEXT:    [[SEL1:%.*]] = call double @llvm.minnum.f64(double [[X:%.*]], 
double 9.000000e-01)
+; CHECK-NEXT:    [[SEL2:%.*]] = call double @llvm.maxnum.f64(double [[SEL1]], 
double 5.000000e-01)
 ; CHECK-NEXT:    ret double [[SEL2]]
 ;
   %cmp1 = fcmp ogt double %x, 9.000000e-01
@@ -284,8 +282,7 @@ define i1 @test_fcmp_ord_select_fcmp_oeq_var_const(double 
%x) {
 
 define float @test_select_nnan_nsz_fcmp_olt(float %x) {
 ; CHECK-LABEL: @test_select_nnan_nsz_fcmp_olt(
-; CHECK-NEXT:    [[TMP1:%.*]] = fcmp olt float [[X:%.*]], -0.000000e+00
-; CHECK-NEXT:    [[SEL1:%.*]] = select i1 [[TMP1]], float [[X]], float 
-0.000000e+00
+; CHECK-NEXT:    [[SEL1:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float -0.000000e+00)
 ; CHECK-NEXT:    ret float [[SEL1]]
 ;
   %cmp = fcmp olt float %x, 0.000000e+00
diff --git a/llvm/test/Transforms/InstCombine/fptrunc.ll 
b/llvm/test/Transforms/InstCombine/fptrunc.ll
index 0b5d8b3cd06e0..faf9ec2aab5f0 100644
--- a/llvm/test/Transforms/InstCombine/fptrunc.ll
+++ b/llvm/test/Transforms/InstCombine/fptrunc.ll
@@ -116,8 +116,9 @@ define half @fptrunc_select_true_val_extra_use(half %x, 
float %y, i1 %cond) {
 
 define half @fptrunc_max(half %arg) {
 ; CHECK-LABEL: @fptrunc_max(
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp olt half [[ARG:%.*]], 0xH0000
-; CHECK-NEXT:    [[NARROW_SEL:%.*]] = select i1 [[CMP]], half 0xH0000, half 
[[ARG]]
+; CHECK-NEXT:    [[EXT:%.*]] = fpext half [[ARG:%.*]] to double
+; CHECK-NEXT:    [[MAX:%.*]] = call double @llvm.maxnum.f64(double [[EXT]], 
double 0.000000e+00)
+; CHECK-NEXT:    [[NARROW_SEL:%.*]] = fptrunc double [[MAX]] to half
 ; CHECK-NEXT:    ret half [[NARROW_SEL]]
 ;
   %ext = fpext half %arg to double
diff --git a/llvm/test/Transforms/InstCombine/load-bitcast-select.ll 
b/llvm/test/Transforms/InstCombine/load-bitcast-select.ll
index 3c43618b13569..8fc30442c2766 100644
--- a/llvm/test/Transforms/InstCombine/load-bitcast-select.ll
+++ b/llvm/test/Transforms/InstCombine/load-bitcast-select.ll
@@ -20,8 +20,7 @@ define void @_Z3foov() {
 ; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw float, ptr @b, 
i64 [[TMP0]]
 ; CHECK-NEXT:    [[TMP1:%.*]] = load float, ptr [[ARRAYIDX]], align 4
 ; CHECK-NEXT:    [[TMP2:%.*]] = load float, ptr [[ARRAYIDX2]], align 4
-; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp fast olt float [[TMP1]], [[TMP2]]
-; CHECK-NEXT:    [[DOTV:%.*]] = select i1 [[CMP_I]], float [[TMP2]], float 
[[TMP1]]
+; CHECK-NEXT:    [[DOTV:%.*]] = call float @llvm.maxnum.f32(float [[TMP2]], 
float [[TMP1]])
 ; CHECK-NEXT:    store float [[DOTV]], ptr [[ARRAYIDX]], align 4
 ; CHECK-NEXT:    [[INC]] = add nuw nsw i32 [[I_0]], 1
 ; CHECK-NEXT:    br label [[FOR_COND]]
@@ -79,8 +78,7 @@ define void @bitcasted_minmax_with_select_of_pointers(ptr 
%loadaddr1, ptr %loada
 ; CHECK-LABEL: @bitcasted_minmax_with_select_of_pointers(
 ; CHECK-NEXT:    [[LD1:%.*]] = load float, ptr [[LOADADDR1:%.*]], align 4
 ; CHECK-NEXT:    [[LD2:%.*]] = load float, ptr [[LOADADDR2:%.*]], align 4
-; CHECK-NEXT:    [[COND:%.*]] = fcmp ogt float [[LD1]], [[LD2]]
-; CHECK-NEXT:    [[LD_V:%.*]] = select i1 [[COND]], float [[LD1]], float 
[[LD2]]
+; CHECK-NEXT:    [[LD_V:%.*]] = call float @llvm.maxnum.f32(float [[LD1]], 
float [[LD2]])
 ; CHECK-NEXT:    store float [[LD_V]], ptr [[STOREADDR:%.*]], align 4
 ; CHECK-NEXT:    ret void
 ;
diff --git a/llvm/test/Transforms/InstCombine/loadstore-metadata.ll 
b/llvm/test/Transforms/InstCombine/loadstore-metadata.ll
index 761129979445c..102e67a126d3c 100644
--- a/llvm/test/Transforms/InstCombine/loadstore-metadata.ll
+++ b/llvm/test/Transforms/InstCombine/loadstore-metadata.ll
@@ -236,8 +236,7 @@ define double 
@preserve_load_metadata_after_select_transform2(ptr %a, ptr %b) {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
 ; CHECK-NEXT:    [[L_A:%.*]] = load double, ptr [[A]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !llvm.access.group [[META6]]
 ; CHECK-NEXT:    [[L_B:%.*]] = load double, ptr [[B]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !llvm.access.group [[META6]]
-; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp fast olt double [[L_A]], [[L_B]]
-; CHECK-NEXT:    [[L_SEL:%.*]] = select i1 [[CMP_I]], double [[L_B]], double 
[[L_A]]
+; CHECK-NEXT:    [[L_SEL:%.*]] = call double @llvm.maxnum.f64(double [[L_B]], 
double [[L_A]])
 ; CHECK-NEXT:    ret double [[L_SEL]]
 ;
 entry:
@@ -255,8 +254,7 @@ define double 
@preserve_load_metadata_after_select_transform_metadata_missing_1(
 ; CHECK-NEXT:  [[ENTRY:.*:]]
 ; CHECK-NEXT:    [[L_A:%.*]] = load double, ptr [[A]], align 8, 
!llvm.access.group [[META6]]
 ; CHECK-NEXT:    [[L_B:%.*]] = load double, ptr [[B]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !llvm.access.group [[META6]]
-; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp fast olt double [[L_A]], [[L_B]]
-; CHECK-NEXT:    [[L_SEL:%.*]] = select i1 [[CMP_I]], double [[L_B]], double 
[[L_A]]
+; CHECK-NEXT:    [[L_SEL:%.*]] = call double @llvm.maxnum.f64(double [[L_B]], 
double [[L_A]])
 ; CHECK-NEXT:    ret double [[L_SEL]]
 ;
 entry:
@@ -274,8 +272,7 @@ define double 
@preserve_load_metadata_after_select_transform_metadata_missing_2(
 ; CHECK-NEXT:  [[ENTRY:.*:]]
 ; CHECK-NEXT:    [[L_A:%.*]] = load double, ptr [[A]], align 8, 
!llvm.access.group [[META6]]
 ; CHECK-NEXT:    [[L_B:%.*]] = load double, ptr [[B]], align 8, 
!llvm.access.group [[META6]]
-; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp fast olt double [[L_A]], [[L_B]]
-; CHECK-NEXT:    [[L_SEL:%.*]] = select i1 [[CMP_I]], double [[L_B]], double 
[[L_A]]
+; CHECK-NEXT:    [[L_SEL:%.*]] = call double @llvm.maxnum.f64(double [[L_B]], 
double [[L_A]])
 ; CHECK-NEXT:    ret double [[L_SEL]]
 ;
 entry:
@@ -293,8 +290,7 @@ define double 
@preserve_load_metadata_after_select_transform_metadata_missing_3(
 ; CHECK-NEXT:  [[ENTRY:.*:]]
 ; CHECK-NEXT:    [[L_A:%.*]] = load double, ptr [[A]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !llvm.access.group [[META6]]
 ; CHECK-NEXT:    [[L_B:%.*]] = load double, ptr [[B]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !llvm.access.group [[META6]]
-; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp fast olt double [[L_A]], [[L_B]]
-; CHECK-NEXT:    [[L_SEL:%.*]] = select i1 [[CMP_I]], double [[L_B]], double 
[[L_A]]
+; CHECK-NEXT:    [[L_SEL:%.*]] = call double @llvm.maxnum.f64(double [[L_B]], 
double [[L_A]])
 ; CHECK-NEXT:    ret double [[L_SEL]]
 ;
 entry:
@@ -314,8 +310,7 @@ define double 
@preserve_load_metadata_after_select_transform_metadata_missing_4(
 ; CHECK-NEXT:  [[ENTRY:.*:]]
 ; CHECK-NEXT:    [[L_A:%.*]] = load double, ptr [[A]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !alias.scope [[META3]], !noalias [[META3]], 
!llvm.access.group [[META6]]
 ; CHECK-NEXT:    [[L_B:%.*]] = load double, ptr [[B]], align 8, !tbaa 
[[SCALAR_TYPE_TBAA0]], !alias.scope [[META12:![0-9]+]], !noalias [[META12]], 
!llvm.access.group [[ACC_GRP15:![0-9]+]]
-; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp fast olt double [[L_A]], [[L_B]]
-; CHECK-NEXT:    [[L_SEL:%.*]] = select i1 [[CMP_I]], double [[L_B]], double 
[[L_A]]
+; CHECK-NEXT:    [[L_SEL:%.*]] = call double @llvm.maxnum.f64(double [[L_B]], 
double [[L_A]])
 ; CHECK-NEXT:    ret double [[L_SEL]]
 ;
 entry:
diff --git a/llvm/test/Transforms/InstCombine/minmax-fold.ll 
b/llvm/test/Transforms/InstCombine/minmax-fold.ll
index a982225370620..38f18b202ed37 100644
--- a/llvm/test/Transforms/InstCombine/minmax-fold.ll
+++ b/llvm/test/Transforms/InstCombine/minmax-fold.ll
@@ -158,8 +158,7 @@ define <4 x i32> @bitcasts_fcmp_1(<2 x i64> %a, <2 x i64> 
%b) {
 ; CHECK-LABEL: @bitcasts_fcmp_1(
 ; CHECK-NEXT:    [[T0:%.*]] = bitcast <2 x i64> [[A:%.*]] to <4 x float>
 ; CHECK-NEXT:    [[T1:%.*]] = bitcast <2 x i64> [[B:%.*]] to <4 x float>
-; CHECK-NEXT:    [[T2:%.*]] = fcmp olt <4 x float> [[T1]], [[T0]]
-; CHECK-NEXT:    [[TMP1:%.*]] = select <4 x i1> [[T2]], <4 x float> [[T0]], <4 
x float> [[T1]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call <4 x float> @llvm.maxnum.v4f32(<4 x 
float> [[T0]], <4 x float> [[T1]])
 ; CHECK-NEXT:    [[T5:%.*]] = bitcast <4 x float> [[TMP1]] to <4 x i32>
 ; CHECK-NEXT:    ret <4 x i32> [[T5]]
 ;
@@ -178,8 +177,7 @@ define <4 x i32> @bitcasts_fcmp_2(<2 x i64> %a, <2 x i64> 
%b) {
 ; CHECK-LABEL: @bitcasts_fcmp_2(
 ; CHECK-NEXT:    [[T0:%.*]] = bitcast <2 x i64> [[A:%.*]] to <4 x float>
 ; CHECK-NEXT:    [[T1:%.*]] = bitcast <2 x i64> [[B:%.*]] to <4 x float>
-; CHECK-NEXT:    [[T2:%.*]] = fcmp olt <4 x float> [[T0]], [[T1]]
-; CHECK-NEXT:    [[TMP1:%.*]] = select <4 x i1> [[T2]], <4 x float> [[T0]], <4 
x float> [[T1]]
+; CHECK-NEXT:    [[TMP1:%.*]] = call <4 x float> @llvm.minnum.v4f32(<4 x 
float> [[T0]], <4 x float> [[T1]])
 ; CHECK-NEXT:    [[T5:%.*]] = bitcast <4 x float> [[TMP1]] to <4 x i32>
 ; CHECK-NEXT:    ret <4 x i32> [[T5]]
 ;
diff --git a/llvm/test/Transforms/InstCombine/minmax-fp.ll 
b/llvm/test/Transforms/InstCombine/minmax-fp.ll
index 9b755b22bb014..18fbeca93a45c 100644
--- a/llvm/test/Transforms/InstCombine/minmax-fp.ll
+++ b/llvm/test/Transforms/InstCombine/minmax-fp.ll
@@ -106,8 +106,7 @@ define double @t7(float %a) {
 
 define float @fmin_fmin_zero_mismatch(float %x) {
 ; CHECK-LABEL: @fmin_fmin_zero_mismatch(
-; CHECK-NEXT:    [[CMP1:%.*]] = fcmp olt float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[MIN2:%.*]] = select i1 [[CMP1]], float [[X]], float 
0.000000e+00
+; CHECK-NEXT:    [[MIN2:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float 0.000000e+00)
 ; CHECK-NEXT:    ret float [[MIN2]]
 ;
   %cmp1 = fcmp olt float %x, -0.0
@@ -215,8 +214,7 @@ define i8 @t14(float %a) {
 
 define i8 @t14_commute(float %a) {
 ; CHECK-LABEL: @t14_commute(
-; CHECK-NEXT:    [[TMP1:%.*]] = fcmp ogt float [[A:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP1]], float [[A]], float 
0.000000e+00
+; CHECK-NEXT:    [[TMP2:%.*]] = call float @llvm.maxnum.f32(float [[A:%.*]], 
float 0.000000e+00)
 ; CHECK-NEXT:    [[TMP3:%.*]] = fptosi float [[TMP2]] to i8
 ; CHECK-NEXT:    ret i8 [[TMP3]]
 ;
@@ -266,8 +264,7 @@ define double @t17(i32 %x) {
 
 define float @fneg_fmax(float %x, float %y) {
 ; CHECK-LABEL: @fneg_fmax(
-; CHECK-NEXT:    [[COND:%.*]] = fcmp nnan olt float [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:    [[MAX_V:%.*]] = select i1 [[COND]], float [[X]], float [[Y]]
+; CHECK-NEXT:    [[MAX_V:%.*]] = call float @llvm.minnum.f32(float [[X:%.*]], 
float [[Y:%.*]])
 ; CHECK-NEXT:    [[MAX:%.*]] = fneg float [[MAX_V]]
 ; CHECK-NEXT:    ret float [[MAX]]
 ;
@@ -280,8 +277,7 @@ define float @fneg_fmax(float %x, float %y) {
 
 define <2 x float> @fsub_fmax(<2 x float> %x, <2 x float> %y) {
 ; CHECK-LABEL: @fsub_fmax(
-; CHECK-NEXT:    [[COND_INV:%.*]] = fcmp nnan nsz ogt <2 x float> [[X:%.*]], 
[[Y:%.*]]
-; CHECK-NEXT:    [[MAX_V:%.*]] = select nnan <2 x i1> [[COND_INV]], <2 x 
float> [[Y]], <2 x float> [[X]]
+; CHECK-NEXT:    [[MAX_V:%.*]] = call nnan <2 x float> @llvm.minnum.v2f32(<2 x 
float> [[Y:%.*]], <2 x float> [[X:%.*]])
 ; CHECK-NEXT:    [[MAX:%.*]] = fneg <2 x float> [[MAX_V]]
 ; CHECK-NEXT:    ret <2 x float> [[MAX]]
 ;
@@ -294,8 +290,7 @@ define <2 x float> @fsub_fmax(<2 x float> %x, <2 x float> 
%y) {
 
 define <2 x double> @fsub_fmin(<2 x double> %x, <2 x double> %y) {
 ; CHECK-LABEL: @fsub_fmin(
-; CHECK-NEXT:    [[COND:%.*]] = fcmp nnan ogt <2 x double> [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT:    [[MAX_V:%.*]] = select <2 x i1> [[COND]], <2 x double> [[X]], 
<2 x double> [[Y]]
+; CHECK-NEXT:    [[MAX_V:%.*]] = call <2 x double> @llvm.maxnum.v2f64(<2 x 
double> [[X:%.*]], <2 x double> [[Y:%.*]])
 ; CHECK-NEXT:    [[MAX:%.*]] = fneg <2 x double> [[MAX_V]]
 ; CHECK-NEXT:    ret <2 x double> [[MAX]]
 ;
@@ -308,8 +303,7 @@ define <2 x double> @fsub_fmin(<2 x double> %x, <2 x 
double> %y) {
 
 define double @fneg_fmin(double %x, double %y) {
 ; CHECK-LABEL: @fneg_fmin(
-; CHECK-NEXT:    [[COND_INV:%.*]] = fcmp nnan nsz olt double [[X:%.*]], 
[[Y:%.*]]
-; CHECK-NEXT:    [[MAX_V:%.*]] = select nnan i1 [[COND_INV]], double [[Y]], 
double [[X]]
+; CHECK-NEXT:    [[MAX_V:%.*]] = call nnan double @llvm.maxnum.f64(double 
[[Y:%.*]], double [[X:%.*]])
 ; CHECK-NEXT:    [[MAX:%.*]] = fneg double [[MAX_V]]
 ; CHECK-NEXT:    ret double [[MAX]]
 ;
@@ -342,8 +336,7 @@ define <2 x float> @maxnum_oge_fmf_on_select(<2 x float> 
%a, <2 x float> %b) {
 
 define float @maxnum_ogt_fmf_on_fcmp(float %a, float %b) {
 ; CHECK-LABEL: @maxnum_ogt_fmf_on_fcmp(
-; CHECK-NEXT:    [[COND:%.*]] = fcmp nnan nsz ogt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[F:%.*]] = select i1 [[COND]], float [[A]], float [[B]]
+; CHECK-NEXT:    [[F:%.*]] = call float @llvm.maxnum.f32(float [[A:%.*]], 
float [[B:%.*]])
 ; CHECK-NEXT:    ret float [[F]]
 ;
   %cond = fcmp nnan nsz ogt float %a, %b
@@ -364,8 +357,7 @@ define <2 x float> @maxnum_oge_fmf_on_fcmp(<2 x float> %a, 
<2 x float> %b) {
 
 define float @maxnum_no_nsz(float %a, float %b) {
 ; CHECK-LABEL: @maxnum_no_nsz(
-; CHECK-NEXT:    [[COND:%.*]] = fcmp ogt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[F:%.*]] = select nnan i1 [[COND]], float [[A]], float [[B]]
+; CHECK-NEXT:    [[F:%.*]] = call nnan float @llvm.maxnum.f32(float [[A:%.*]], 
float [[B:%.*]])
 ; CHECK-NEXT:    ret float [[F]]
 ;
   %cond = fcmp ogt float %a, %b
@@ -416,8 +408,7 @@ define <2 x float> @minnum_ole_fmf_on_select(<2 x float> 
%a, <2 x float> %b) {
 
 define float @minnum_olt_fmf_on_fcmp(float %a, float %b) {
 ; CHECK-LABEL: @minnum_olt_fmf_on_fcmp(
-; CHECK-NEXT:    [[COND:%.*]] = fcmp nnan nsz olt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[F:%.*]] = select i1 [[COND]], float [[A]], float [[B]]
+; CHECK-NEXT:    [[F:%.*]] = call float @llvm.minnum.f32(float [[A:%.*]], 
float [[B:%.*]])
 ; CHECK-NEXT:    ret float [[F]]
 ;
   %cond = fcmp nnan nsz olt float %a, %b
@@ -438,8 +429,7 @@ define <2 x float> @minnum_ole_fmf_on_fcmp(<2 x float> %a, 
<2 x float> %b) {
 
 define float @minnum_no_nsz(float %a, float %b) {
 ; CHECK-LABEL: @minnum_no_nsz(
-; CHECK-NEXT:    [[COND:%.*]] = fcmp olt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[F:%.*]] = select nnan i1 [[COND]], float [[A]], float [[B]]
+; CHECK-NEXT:    [[F:%.*]] = call nnan float @llvm.minnum.f32(float [[A:%.*]], 
float [[B:%.*]])
 ; CHECK-NEXT:    ret float [[F]]
 ;
   %cond = fcmp olt float %a, %b
@@ -460,8 +450,7 @@ define float @minnum_no_nnan(float %a, float %b) {
 
 define float @pr64937_preserve_min_idiom(float %a) {
 ; CHECK-LABEL: @pr64937_preserve_min_idiom(
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp nnan olt float [[A:%.*]], 3.276700e+04
-; CHECK-NEXT:    [[SEL:%.*]] = select nnan i1 [[CMP]], float [[A]], float 
3.276700e+04
+; CHECK-NEXT:    [[SEL:%.*]] = call nnan float @llvm.minnum.f32(float 
[[A:%.*]], float 3.276700e+04)
 ; CHECK-NEXT:    [[RES:%.*]] = fmul nnan float [[SEL]], 6.553600e+04
 ; CHECK-NEXT:    ret float [[RES]]
 ;
diff --git 
a/llvm/test/Transforms/InstCombine/multiple-uses-load-bitcast-select.ll 
b/llvm/test/Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
index 5d3512e10f418..b5a9ee269b9e8 100644
--- a/llvm/test/Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
+++ b/llvm/test/Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
@@ -5,8 +5,7 @@ define void @PR35618(ptr %st1, ptr %st2, ptr %y1, ptr %z1) {
 ; CHECK-LABEL: @PR35618(
 ; CHECK-NEXT:    [[LD1:%.*]] = load double, ptr [[Y1:%.*]], align 8
 ; CHECK-NEXT:    [[LD2:%.*]] = load double, ptr [[Z1:%.*]], align 8
-; CHECK-NEXT:    [[TMP:%.*]] = fcmp olt double [[LD1]], [[LD2]]
-; CHECK-NEXT:    [[TMP12_V:%.*]] = select i1 [[TMP]], double [[LD1]], double 
[[LD2]]
+; CHECK-NEXT:    [[TMP12_V:%.*]] = call double @llvm.minnum.f64(double 
[[LD1]], double [[LD2]])
 ; CHECK-NEXT:    store double [[TMP12_V]], ptr [[ST1:%.*]], align 8
 ; CHECK-NEXT:    store double [[TMP12_V]], ptr [[ST2:%.*]], align 8
 ; CHECK-NEXT:    ret void
@@ -25,8 +24,7 @@ define void @PR35618_asan(ptr %st1, ptr %st2, ptr %y1, ptr 
%z1) sanitize_address
 ; CHECK-LABEL: @PR35618_asan(
 ; CHECK-NEXT:    [[LD1:%.*]] = load double, ptr [[Y1:%.*]], align 8
 ; CHECK-NEXT:    [[LD2:%.*]] = load double, ptr [[Z1:%.*]], align 8
-; CHECK-NEXT:    [[TMP:%.*]] = fcmp olt double [[LD1]], [[LD2]]
-; CHECK-NEXT:    [[TMP12_V:%.*]] = select i1 [[TMP]], double [[LD1]], double 
[[LD2]]
+; CHECK-NEXT:    [[TMP12_V:%.*]] = call double @llvm.minnum.f64(double 
[[LD1]], double [[LD2]])
 ; CHECK-NEXT:    store double [[TMP12_V]], ptr [[ST1:%.*]], align 8
 ; CHECK-NEXT:    store double [[TMP12_V]], ptr [[ST2:%.*]], align 8
 ; CHECK-NEXT:    ret void
diff --git a/llvm/test/Transforms/InstCombine/select-select.ll 
b/llvm/test/Transforms/InstCombine/select-select.ll
index 94e88c2f6cbe6..6300ad59e882e 100644
--- a/llvm/test/Transforms/InstCombine/select-select.ll
+++ b/llvm/test/Transforms/InstCombine/select-select.ll
@@ -3,10 +3,8 @@
 
 define float @foo1(float %a) {
 ; CHECK-LABEL: @foo1(
-; CHECK-NEXT:    [[B:%.*]] = fcmp ogt float [[A:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[C:%.*]] = select i1 [[B]], float [[A]], float 0.000000e+00
-; CHECK-NEXT:    [[D:%.*]] = fcmp olt float [[C]], 1.000000e+00
-; CHECK-NEXT:    [[F:%.*]] = select i1 [[D]], float [[C]], float 1.000000e+00
+; CHECK-NEXT:    [[C:%.*]] = call float @llvm.maxnum.f32(float [[A:%.*]], 
float 0.000000e+00)
+; CHECK-NEXT:    [[F:%.*]] = call float @llvm.minnum.f32(float [[C]], float 
1.000000e+00)
 ; CHECK-NEXT:    ret float [[F]]
 ;
   %b = fcmp ogt float %a, 0.0
@@ -19,8 +17,7 @@ define float @foo1(float %a) {
 define float @foo2(float %a) {
 ; CHECK-LABEL: @foo2(
 ; CHECK-NEXT:    [[B:%.*]] = fcmp ule float [[A:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[TMP1:%.*]] = fcmp olt float [[A]], 1.000000e+00
-; CHECK-NEXT:    [[E:%.*]] = select i1 [[TMP1]], float [[A]], float 
1.000000e+00
+; CHECK-NEXT:    [[E:%.*]] = call float @llvm.minnum.f32(float [[A]], float 
1.000000e+00)
 ; CHECK-NEXT:    [[F:%.*]] = select i1 [[B]], float 0.000000e+00, float [[E]]
 ; CHECK-NEXT:    ret float [[F]]
 ;
diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll 
b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll
index df60078dbf452..9d56a9ce8ce31 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll
@@ -851,8 +851,7 @@ define nofpclass(nan pinf pnorm psub pzero) float 
@ret_nofpclass_no_positives_no
 define nofpclass(ninf nnorm nsub nzero) float 
@ret_nofpclass_negatives__select_clamp_neg_to_zero(float %x) {
 ; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float 
@ret_nofpclass_negatives__select_clamp_neg_to_zero
 ; CHECK-SAME: (float [[X:%.*]]) {
-; CHECK-NEXT:    [[IS_LT_ZERO:%.*]] = fcmp olt float [[X]], 0.000000e+00
-; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[IS_LT_ZERO]], float 
0.000000e+00, float [[X]]
+; CHECK-NEXT:    [[SELECT:%.*]] = call float @llvm.maxnum.f32(float [[X]], 
float 0.000000e+00)
 ; CHECK-NEXT:    ret float [[SELECT]]
 ;
   %is.lt.zero = fcmp olt float %x, 0.0
@@ -864,9 +863,7 @@ define nofpclass(ninf nnorm nsub nzero) float 
@ret_nofpclass_negatives__select_c
 define nofpclass(ninf nnorm nsub nzero) float 
@ret_nofpclass_negatives__select_clamp_pos_to_zero(float %x) {
 ; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) float 
@ret_nofpclass_negatives__select_clamp_pos_to_zero
 ; CHECK-SAME: (float [[X:%.*]]) {
-; CHECK-NEXT:    [[IS_GT_ZERO:%.*]] = fcmp ogt float [[X]], 0.000000e+00
-; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[IS_GT_ZERO]], float 
0.000000e+00, float [[X]]
-; CHECK-NEXT:    ret float [[SELECT]]
+; CHECK-NEXT:    ret float 0.000000e+00
 ;
   %is.gt.zero = fcmp ogt float %x, 0.0
   %select = select i1 %is.gt.zero, float 0.0, float %x
@@ -877,9 +874,7 @@ define nofpclass(ninf nnorm nsub nzero) float 
@ret_nofpclass_negatives__select_c
 define nofpclass(nan ninf nnorm nsub nzero) float 
@ret_nofpclass_nan_negatives__select_clamp_pos_to_zero(float %x) {
 ; CHECK-LABEL: define nofpclass(nan ninf nzero nsub nnorm) float 
@ret_nofpclass_nan_negatives__select_clamp_pos_to_zero
 ; CHECK-SAME: (float [[X:%.*]]) {
-; CHECK-NEXT:    [[IS_GT_ZERO:%.*]] = fcmp ogt float [[X]], 0.000000e+00
-; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[IS_GT_ZERO]], float 
0.000000e+00, float [[X]]
-; CHECK-NEXT:    ret float [[SELECT]]
+; CHECK-NEXT:    ret float 0.000000e+00
 ;
   %is.gt.zero = fcmp ogt float %x, 0.0
   %select = select i1 %is.gt.zero, float 0.0, float %x
@@ -890,7 +885,7 @@ define nofpclass(nan ninf nnorm nsub nzero) float 
@ret_nofpclass_nan_negatives__
 define nofpclass(nan ninf nnorm nsub zero) float 
@ret_nofpclass_nan_negatives_zero__select_clamp_pos_to_zero(float %x) {
 ; CHECK-LABEL: define nofpclass(nan ninf zero nsub nnorm) float 
@ret_nofpclass_nan_negatives_zero__select_clamp_pos_to_zero
 ; CHECK-SAME: (float [[X:%.*]]) {
-; CHECK-NEXT:    ret float [[X]]
+; CHECK-NEXT:    ret float poison
 ;
   %is.gt.zero = fcmp ogt float %x, 0.0
   %select = select i1 %is.gt.zero, float 0.0, float %x
@@ -901,7 +896,7 @@ define nofpclass(nan ninf nnorm nsub zero) float 
@ret_nofpclass_nan_negatives_ze
 define nofpclass(ninf nnorm nsub zero) float 
@ret_nofpclass_negatives_zero__select_clamp_pos_to_zero(float %x) {
 ; CHECK-LABEL: define nofpclass(ninf zero nsub nnorm) float 
@ret_nofpclass_negatives_zero__select_clamp_pos_to_zero
 ; CHECK-SAME: (float [[X:%.*]]) {
-; CHECK-NEXT:    ret float [[X]]
+; CHECK-NEXT:    ret float poison
 ;
   %is.gt.zero = fcmp ogt float %x, 0.0
   %select = select i1 %is.gt.zero, float 0.0, float %x
diff --git a/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll 
b/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
index ad86f2ed2fa59..3c21b4b6ec049 100644
--- a/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll
@@ -14,8 +14,7 @@ define float @select_max_ugt(float %a, float %b) {
 
 define float @select_max_uge(float %a, float %b) {
 ; CHECK-LABEL: @select_max_uge(
-; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp nnan olt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[SEL:%.*]] = select nnan ninf i1 [[CMP_INV]], float [[B]], 
float [[A]]
+; CHECK-NEXT:    [[SEL:%.*]] = call nnan ninf float @llvm.maxnum.f32(float 
[[B:%.*]], float [[A:%.*]])
 ; CHECK-NEXT:    ret float [[SEL]]
 ;
   %cmp = fcmp nnan uge float %a, %b
@@ -77,8 +76,7 @@ define float @select_min_ult(float %a, float %b) {
 
 define float @select_min_ule(float %a, float %b) {
 ; CHECK-LABEL: @select_min_ule(
-; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp arcp ogt float [[A:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[SEL:%.*]] = select ninf i1 [[CMP_INV]], float [[B]], float 
[[A]]
+; CHECK-NEXT:    [[SEL:%.*]] = call ninf float @llvm.minnum.f32(float 
[[B:%.*]], float [[A:%.*]])
 ; CHECK-NEXT:    ret float [[SEL]]
 ;
   %cmp = fcmp arcp ule float %a, %b
diff --git a/llvm/test/Transforms/PhaseOrdering/X86/preserve-access-group.ll 
b/llvm/test/Transforms/PhaseOrdering/X86/preserve-access-group.ll
index ac736518c0cbd..7d4518bb476d2 100644
--- a/llvm/test/Transforms/PhaseOrdering/X86/preserve-access-group.ll
+++ b/llvm/test/Transforms/PhaseOrdering/X86/preserve-access-group.ll
@@ -32,9 +32,8 @@ define void @test(i32 noundef %nface, i32 noundef %ncell, ptr 
noalias noundef %f
 ; CHECK-NEXT:    [[TMP6:%.*]] = getelementptr inbounds double, ptr [[X]], <4 x 
i64> [[TMP5]]
 ; CHECK-NEXT:    [[WIDE_MASKED_GATHER:%.*]] = tail call <4 x double> 
@llvm.masked.gather.v4f64.v4p0(<4 x ptr> [[TMP4]], i32 8, <4 x i1> splat (i1 
true), <4 x double> poison), !tbaa [[DOUBLE_TBAA5:![0-9]+]], !llvm.access.group 
[[ACC_GRP4]]
 ; CHECK-NEXT:    [[WIDE_MASKED_GATHER13:%.*]] = tail call <4 x double> 
@llvm.masked.gather.v4f64.v4p0(<4 x ptr> [[TMP6]], i32 8, <4 x i1> splat (i1 
true), <4 x double> poison), !tbaa [[DOUBLE_TBAA5]], !llvm.access.group 
[[ACC_GRP4]]
-; CHECK-NEXT:    [[TMP7:%.*]] = fcmp fast olt <4 x double> 
[[WIDE_MASKED_GATHER]], [[WIDE_MASKED_GATHER13]]
-; CHECK-NEXT:    [[TMP8:%.*]] = select <4 x i1> [[TMP7]], <4 x double> 
[[WIDE_MASKED_GATHER13]], <4 x double> [[WIDE_MASKED_GATHER]]
-; CHECK-NEXT:    tail call void @llvm.masked.scatter.v4f64.v4p0(<4 x double> 
[[TMP8]], <4 x ptr> [[TMP4]], i32 8, <4 x i1> splat (i1 true)), !tbaa 
[[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
+; CHECK-NEXT:    [[TMP7:%.*]] = tail call <4 x double> @llvm.maxnum.v4f64(<4 x 
double> [[WIDE_MASKED_GATHER13]], <4 x double> [[WIDE_MASKED_GATHER]])
+; CHECK-NEXT:    tail call void @llvm.masked.scatter.v4f64.v4p0(<4 x double> 
[[TMP7]], <4 x ptr> [[TMP4]], i32 8, <4 x i1> splat (i1 true)), !tbaa 
[[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
 ; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDVARS_IV_EPIL]], 4
 ; CHECK-NEXT:    [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[UNROLL_ITER]]
 ; CHECK-NEXT:    br i1 [[TMP9]], label %[[MIDDLE_BLOCK:.*]], label 
%[[VECTOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
@@ -56,11 +55,10 @@ define void @test(i32 noundef %nface, i32 noundef %ncell, 
ptr noalias noundef %f
 ; CHECK-NEXT:    [[ARRAYIDX4_3:%.*]] = getelementptr inbounds double, ptr 
[[Y]], i64 [[IDXPROM3_3]]
 ; CHECK-NEXT:    [[IDXPROM5_3:%.*]] = sext i32 [[TMP23]] to i64
 ; CHECK-NEXT:    [[ARRAYIDX6_3:%.*]] = getelementptr inbounds double, ptr 
[[X]], i64 [[IDXPROM5_3]]
-; CHECK-NEXT:    [[TMP24:%.*]] = load double, ptr [[ARRAYIDX4_3]], align 8, 
!tbaa [[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
-; CHECK-NEXT:    [[TMP25:%.*]] = load double, ptr [[ARRAYIDX6_3]], align 8, 
!tbaa [[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
-; CHECK-NEXT:    [[CMP_I_3:%.*]] = fcmp fast olt double [[TMP24]], [[TMP25]]
-; CHECK-NEXT:    [[TMP26:%.*]] = select i1 [[CMP_I_3]], double [[TMP25]], 
double [[TMP24]]
-; CHECK-NEXT:    store double [[TMP26]], ptr [[ARRAYIDX4_3]], align 8, !tbaa 
[[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
+; CHECK-NEXT:    [[TMP11:%.*]] = load double, ptr [[ARRAYIDX4_3]], align 8, 
!tbaa [[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
+; CHECK-NEXT:    [[TMP12:%.*]] = load double, ptr [[ARRAYIDX6_3]], align 8, 
!tbaa [[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
+; CHECK-NEXT:    [[TMP13:%.*]] = tail call double @llvm.maxnum.f64(double 
[[TMP12]], double [[TMP11]])
+; CHECK-NEXT:    store double [[TMP13]], ptr [[ARRAYIDX4_3]], align 8, !tbaa 
[[DOUBLE_TBAA5]], !llvm.access.group [[ACC_GRP4]]
 ; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV_NEXT_2]], 1
 ; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 
[[TMP0]]
 ; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label %[[FOR_COND_CLEANUP]], label 
%[[FOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]]
diff --git a/llvm/test/Transforms/PhaseOrdering/simplifycfg-options.ll 
b/llvm/test/Transforms/PhaseOrdering/simplifycfg-options.ll
index ba71299d6919e..3200edf4807e0 100644
--- a/llvm/test/Transforms/PhaseOrdering/simplifycfg-options.ll
+++ b/llvm/test/Transforms/PhaseOrdering/simplifycfg-options.ll
@@ -74,8 +74,7 @@ define double @max_of_loads(ptr %x, ptr %y, i64 %i) {
 ; CHECK-NEXT:    [[YI_PTR:%.*]] = getelementptr double, ptr [[Y:%.*]], i64 
[[I]]
 ; CHECK-NEXT:    [[XI:%.*]] = load double, ptr [[XI_PTR]], align 8
 ; CHECK-NEXT:    [[YI:%.*]] = load double, ptr [[YI_PTR]], align 8
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt double [[XI]], [[YI]]
-; CHECK-NEXT:    [[XI_YI:%.*]] = select i1 [[CMP]], double [[XI]], double 
[[YI]]
+; CHECK-NEXT:    [[XI_YI:%.*]] = tail call double @llvm.maxnum.f64(double 
[[XI]], double [[YI]])
 ; CHECK-NEXT:    ret double [[XI_YI]]
 ;
 entry:

>From 89e68b2b2952862d5078d55c26d1e2bdb11071ee Mon Sep 17 00:00:00 2001
From: vedantparanjape <vedantparanjape160...@gmail.com>
Date: Thu, 18 Sep 2025 17:23:23 -0400
Subject: [PATCH 2/3] run clang format

---
 llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 028a432cdba44..ade78b3c50de4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -4010,8 +4010,9 @@ static Value *foldSelectICmpIntoMaxMin(SelectInst &SI,
   // Note: OneUse check for `Cmp` is necessary because it makes sure that other
   // InstCombine folds don't undo this transformation and cause an infinite
   // loop. Furthermore, it could also increase the operation count.
-  if (match(&SI, m_OneUse(m_Select(m_OneUse(m_FCmp(Pred, m_Value(X), 
m_Value(Y))),
-                          m_Value(TVal), m_Value(FVal)))))
+  if (match(&SI,
+            m_OneUse(m_Select(m_OneUse(m_FCmp(Pred, m_Value(X), m_Value(Y))),
+                              m_Value(TVal), m_Value(FVal)))))
     return TryFoldIntoMaxMinIntrinsic(Pred, X, Y, TVal, FVal);
 
   return nullptr;

>From 76a30985a10ddb3454ba2aa4f942c4622c735cd0 Mon Sep 17 00:00:00 2001
From: vedantparanjape <vedantparanjape160...@gmail.com>
Date: Thu, 18 Sep 2025 18:53:20 -0400
Subject: [PATCH 3/3] updated hip and aarch64 testcase

---
 clang/test/Headers/__clang_hip_math.hip       | 25 ++++++++-----------
 ...ting-sinking-required-for-vectorization.ll |  9 +++----
 2 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index b88aa3cc18207..54aada875bb62 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -8734,47 +8734,42 @@ extern "C" __device__ float test___powf(float x, float 
y) {
 }
 
 // DEFAULT-LABEL: define dso_local noundef float @test___saturatef(
-// DEFAULT-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR3]] {
+// DEFAULT-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] 
{
 // DEFAULT-NEXT:  [[ENTRY:.*:]]
 // DEFAULT-NEXT:    [[CMP_I:%.*]] = fcmp contract olt float [[X]], 0.000000e+00
-// DEFAULT-NEXT:    [[CMP1_I:%.*]] = fcmp contract ogt float [[X]], 
1.000000e+00
-// DEFAULT-NEXT:    [[COND_I:%.*]] = select contract i1 [[CMP1_I]], float 
1.000000e+00, float [[X]]
+// DEFAULT-NEXT:    [[COND_I:%.*]] = tail call contract float 
@llvm.minnum.f32(float [[X]], float 1.000000e+00)
 // DEFAULT-NEXT:    [[COND5_I:%.*]] = select contract i1 [[CMP_I]], float 
0.000000e+00, float [[COND_I]]
 // DEFAULT-NEXT:    ret float [[COND5_I]]
 //
 // FINITEONLY-LABEL: define dso_local nofpclass(nan inf) float 
@test___saturatef(
-// FINITEONLY-SAME: float noundef nofpclass(nan inf) [[X:%.*]]) 
local_unnamed_addr #[[ATTR3]] {
+// FINITEONLY-SAME: float noundef nofpclass(nan inf) [[X:%.*]]) 
local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // FINITEONLY-NEXT:  [[ENTRY:.*:]]
 // FINITEONLY-NEXT:    [[CMP_I:%.*]] = fcmp nnan ninf contract olt float 
[[X]], 0.000000e+00
-// FINITEONLY-NEXT:    [[CMP1_I:%.*]] = fcmp nnan ninf contract ogt float 
[[X]], 1.000000e+00
-// FINITEONLY-NEXT:    [[COND_I:%.*]] = select nnan ninf contract i1 
[[CMP1_I]], float 1.000000e+00, float [[X]]
+// FINITEONLY-NEXT:    [[COND_I:%.*]] = tail call nnan ninf contract float 
@llvm.minnum.f32(float nofpclass(nan inf) [[X]], float 1.000000e+00)
 // FINITEONLY-NEXT:    [[COND5_I:%.*]] = select nnan ninf contract i1 
[[CMP_I]], float 0.000000e+00, float [[COND_I]]
 // FINITEONLY-NEXT:    ret float [[COND5_I]]
 //
 // APPROX-LABEL: define dso_local noundef float @test___saturatef(
-// APPROX-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR3]] {
+// APPROX-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // APPROX-NEXT:  [[ENTRY:.*:]]
 // APPROX-NEXT:    [[CMP_I:%.*]] = fcmp contract olt float [[X]], 0.000000e+00
-// APPROX-NEXT:    [[CMP1_I:%.*]] = fcmp contract ogt float [[X]], 1.000000e+00
-// APPROX-NEXT:    [[COND_I:%.*]] = select contract i1 [[CMP1_I]], float 
1.000000e+00, float [[X]]
+// APPROX-NEXT:    [[COND_I:%.*]] = tail call contract float 
@llvm.minnum.f32(float [[X]], float 1.000000e+00)
 // APPROX-NEXT:    [[COND5_I:%.*]] = select contract i1 [[CMP_I]], float 
0.000000e+00, float [[COND_I]]
 // APPROX-NEXT:    ret float [[COND5_I]]
 //
 // NCRDIV-LABEL: define dso_local noundef float @test___saturatef(
-// NCRDIV-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR3]] {
+// NCRDIV-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] {
 // NCRDIV-NEXT:  [[ENTRY:.*:]]
 // NCRDIV-NEXT:    [[CMP_I:%.*]] = fcmp contract olt float [[X]], 0.000000e+00
-// NCRDIV-NEXT:    [[CMP1_I:%.*]] = fcmp contract ogt float [[X]], 1.000000e+00
-// NCRDIV-NEXT:    [[COND_I:%.*]] = select contract i1 [[CMP1_I]], float 
1.000000e+00, float [[X]]
+// NCRDIV-NEXT:    [[COND_I:%.*]] = tail call contract float 
@llvm.minnum.f32(float [[X]], float 1.000000e+00)
 // NCRDIV-NEXT:    [[COND5_I:%.*]] = select contract i1 [[CMP_I]], float 
0.000000e+00, float [[COND_I]]
 // NCRDIV-NEXT:    ret float [[COND5_I]]
 //
 // AMDGCNSPIRV-LABEL: define spir_func noundef float @test___saturatef(
-// AMDGCNSPIRV-SAME: float noundef [[X:%.*]]) local_unnamed_addr addrspace(4) 
#[[ATTR3]] {
+// AMDGCNSPIRV-SAME: float noundef [[X:%.*]]) local_unnamed_addr addrspace(4) 
#[[ATTR2:[0-9]+]] {
 // AMDGCNSPIRV-NEXT:  [[ENTRY:.*:]]
 // AMDGCNSPIRV-NEXT:    [[CMP_I:%.*]] = fcmp contract olt float [[X]], 
0.000000e+00
-// AMDGCNSPIRV-NEXT:    [[CMP1_I:%.*]] = fcmp contract ogt float [[X]], 
1.000000e+00
-// AMDGCNSPIRV-NEXT:    [[COND_I:%.*]] = select contract i1 [[CMP1_I]], float 
1.000000e+00, float [[X]]
+// AMDGCNSPIRV-NEXT:    [[COND_I:%.*]] = tail call contract addrspace(4) float 
@llvm.minnum.f32(float [[X]], float 1.000000e+00)
 // AMDGCNSPIRV-NEXT:    [[COND5_I:%.*]] = select contract i1 [[CMP_I]], float 
0.000000e+00, float [[COND_I]]
 // AMDGCNSPIRV-NEXT:    ret float [[COND5_I]]
 //
diff --git 
a/llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
 
b/llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
index e74bf592e1525..99ef74ec41f94 100644
--- 
a/llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
+++ 
b/llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll
@@ -54,10 +54,8 @@ define void @loop(ptr %X, ptr %Y) {
 ; CHECK-NEXT:    [[WIDE_LOAD8:%.*]] = load <2 x double>, ptr [[TMP2]], align 8
 ; CHECK-NEXT:    [[TMP3:%.*]] = fcmp olt <2 x double> [[WIDE_LOAD]], 
zeroinitializer
 ; CHECK-NEXT:    [[TMP4:%.*]] = fcmp olt <2 x double> [[WIDE_LOAD8]], 
zeroinitializer
-; CHECK-NEXT:    [[TMP5:%.*]] = fcmp ogt <2 x double> [[WIDE_LOAD]], splat 
(double 6.000000e+00)
-; CHECK-NEXT:    [[TMP6:%.*]] = fcmp ogt <2 x double> [[WIDE_LOAD8]], splat 
(double 6.000000e+00)
-; CHECK-NEXT:    [[TMP7:%.*]] = select <2 x i1> [[TMP5]], <2 x double> splat 
(double 6.000000e+00), <2 x double> [[WIDE_LOAD]]
-; CHECK-NEXT:    [[TMP8:%.*]] = select <2 x i1> [[TMP6]], <2 x double> splat 
(double 6.000000e+00), <2 x double> [[WIDE_LOAD8]]
+; CHECK-NEXT:    [[TMP7:%.*]] = tail call <2 x double> @llvm.minnum.v2f64(<2 x 
double> [[WIDE_LOAD]], <2 x double> splat (double 6.000000e+00))
+; CHECK-NEXT:    [[TMP8:%.*]] = tail call <2 x double> @llvm.minnum.v2f64(<2 x 
double> [[WIDE_LOAD8]], <2 x double> splat (double 6.000000e+00))
 ; CHECK-NEXT:    [[TMP9:%.*]] = select <2 x i1> [[TMP3]], <2 x double> 
zeroinitializer, <2 x double> [[TMP7]]
 ; CHECK-NEXT:    [[TMP10:%.*]] = select <2 x i1> [[TMP4]], <2 x double> 
zeroinitializer, <2 x double> [[TMP8]]
 ; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr inbounds nuw double, ptr [[X]], 
i64 [[INDEX]]
@@ -74,8 +72,7 @@ define void @loop(ptr %X, ptr %Y) {
 ; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw double, ptr 
[[Y]], i64 [[INDVARS_IV]]
 ; CHECK-NEXT:    [[TMP14:%.*]] = load double, ptr [[ARRAYIDX]], align 8
 ; CHECK-NEXT:    [[CMP_I:%.*]] = fcmp olt double [[TMP14]], 0.000000e+00
-; CHECK-NEXT:    [[CMP1_I:%.*]] = fcmp ogt double [[TMP14]], 6.000000e+00
-; CHECK-NEXT:    [[DOTV_I:%.*]] = select i1 [[CMP1_I]], double 6.000000e+00, 
double [[TMP14]]
+; CHECK-NEXT:    [[DOTV_I:%.*]] = tail call double @llvm.minnum.f64(double 
[[TMP14]], double 6.000000e+00)
 ; CHECK-NEXT:    [[RETVAL_0_I:%.*]] = select i1 [[CMP_I]], double 
0.000000e+00, double [[DOTV_I]]
 ; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds nuw double, ptr 
[[X]], i64 [[INDVARS_IV]]
 ; CHECK-NEXT:    store double [[RETVAL_0_I]], ptr [[ARRAYIDX2]], align 8

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to