aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-09-15 11:31:28 +0200
committerNikita Popov <npopov@redhat.com>2023-09-15 13:50:08 +0200
commitab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5 (patch)
treebf5f6a10ae8b63da32cbb2877ad4eca88fff78e0 /llvm/lib/IR/ConstantRange.cpp
parent73371faf05887fbe84916456b7c200b07978e7b5 (diff)
downloadllvm-ab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5.zip
llvm-ab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5.tar.gz
llvm-ab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5.tar.bz2
[ConstantRange] Optimize smul nowrap with constant (NFC)
Don't call makeExactMulNSWRegion() twice with the same value.
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index d22d56e..3d71b20 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()));