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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 09:34:13 PST 2023


================
@@ -1796,6 +1796,19 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     if (Instruction *NewMinMax = factorizeMinMaxTree(II))
        return NewMinMax;
 
+    // Try to fold minmax based on range information
+    ICmpInst::Predicate Pred =
+        ICmpInst::getNonStrictPredicate(MinMaxIntrinsic::getPredicate(IID));
+    bool IsSigned = MinMaxIntrinsic::isSigned(IID);
+    const auto LHS_CR = llvm::computeConstantRangeIncludingKnownBits(
+        I0, IsSigned, SQ.getWithInstruction(II));
----------------
nikic wrote:

Yeah, just handling constants make sense.

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


More information about the llvm-commits mailing list