[llvm] [InstCombine] Fold fcmp eq over min/max-like select into compare on input (PR #188226)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu May 7 11:47:44 PDT 2026


================
@@ -8952,6 +8952,80 @@ static Instruction *foldFCmpWithFloorAndCeil(FCmpInst &I,
   return nullptr;
 }
 
+/// Fold equality compares against OGT/OGE-driven min/max-like selects:
+///   fcmp oeq/ueq (select (fcmp ogt/oge X, K), X, K), C
+///   fcmp oeq/ueq (select (fcmp ogt/oge X, K), K, X), C
+///
+/// Where one select arm is the compare bound constant K and the other is X.
+/// This performs a local one-step simplification based on C vs K:
+///   max-like select:
+///     C > K  -> X == C
+///     C == K -> X <= K
+///   min-like select:
+///     C < K  -> X == C
+///     C == K -> X >= K
+///
+static Instruction *
+foldFCmpEqWithMinMaxLikeSelect(FCmpInst &I, Instruction *LHSI, Constant *RHSC) {
+  const FCmpInst::Predicate Pred = I.getPredicate();
+  if (Pred != FCmpInst::FCMP_OEQ && Pred != FCmpInst::FCMP_UEQ)
+    return nullptr;
+
+  auto *SI = dyn_cast<SelectInst>(LHSI);
----------------
nikic wrote:

Do not introduce new uses of matchSelectPattern.

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


More information about the llvm-commits mailing list