[Mlir-commits] [mlir] 3deee23 - [mlir] IntegerRangeAnalysis: don't loop over splat attr (#115229)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Nov 7 12:14:33 PST 2024


Author: Ian Wood
Date: 2024-11-07T12:14:29-08:00
New Revision: 3deee235986802694175259e078dfad0edcb40ed

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

LOG: [mlir] IntegerRangeAnalysis: don't loop over splat attr  (#115229)

If the `DenseIntElementsAttr` is a splat value, there is no need to loop
over the entire attr. Instead, just update with the splat value.

Added: 
    

Modified: 
    mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
index 8682294c8a6972..59c9759d35393f 100644
--- a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
+++ b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
@@ -40,6 +40,11 @@ void arith::ConstantOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
     setResultRange(getResult(), ConstantIntRanges::constant(value));
     return;
   }
+  if (auto splatAttr = llvm::dyn_cast_or_null<SplatElementsAttr>(getValue())) {
+    setResultRange(getResult(), ConstantIntRanges::constant(
+                                    splatAttr.getSplatValue<APInt>()));
+    return;
+  }
   if (auto arrayCstAttr =
           llvm::dyn_cast_or_null<DenseIntElementsAttr>(getValue())) {
     std::optional<ConstantIntRanges> result;


        


More information about the Mlir-commits mailing list