[llvm] ab6667f - [ConstantRange] Optimize smul nowrap with constant (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 04:50:40 PDT 2023


Author: Nikita Popov
Date: 2023-09-15T13:50:08+02:00
New Revision: ab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5

URL: https://github.com/llvm/llvm-project/commit/ab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5
DIFF: https://github.com/llvm/llvm-project/commit/ab6667f844e2a5e072bf9710b09fdb7b5ebd8cc5.diff

LOG: [ConstantRange] Optimize smul nowrap with constant (NFC)

Don't call makeExactMulNSWRegion() twice with the same value.

Added: 
    

Modified: 
    llvm/lib/IR/ConstantRange.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index d22d56e40c08f20..3d71b20f7e853e0 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()));
 


        


More information about the llvm-commits mailing list