diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index d22d56e40c08f..3d71b20f7e853 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -326,6 +326,10 @@ ConstantRange::makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, if (Unsigned) return makeExactMulNUWRegion(Other.getUnsignedMax()); + // Avoid one makeExactMulNSWRegion() call for the common case of constants. + if (const APInt *C = Other.getSingleElement()) + return makeExactMulNSWRegion(*C); + return makeExactMulNSWRegion(Other.getSignedMin()) .intersectWith(makeExactMulNSWRegion(Other.getSignedMax()));