[llvm] [InstCombine] Fold minmax intrinsic using KnownBits information (PR #76242)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 11:32:11 PST 2023


================
@@ -1796,6 +1796,23 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     if (Instruction *NewMinMax = factorizeMinMaxTree(II))
        return NewMinMax;
 
+    // Try to fold minmax with constant RHS based on range information
+    const APInt *RHSC;
+    if (match(I1, m_APIntAllowUndef(RHSC))) {
+      ICmpInst::Predicate Pred =
+          ICmpInst::getNonStrictPredicate(MinMaxIntrinsic::getPredicate(IID));
+      bool IsSigned = MinMaxIntrinsic::isSigned(IID);
+      const auto LHS_CR = llvm::computeConstantRangeIncludingKnownBits(
----------------
nikic wrote:

```suggestion
      ConstantRange LHS_CR = computeConstantRangeIncludingKnownBits(
```

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


More information about the llvm-commits mailing list