[Mlir-commits] [mlir] [mlir] IntegerRangeAnalysis: don't loop over splat attr (PR #115399)

Ian Wood llvmlistbot at llvm.org
Thu Nov 7 16:05:28 PST 2024


https://github.com/IanWood1 created https://github.com/llvm/llvm-project/pull/115399

Reland https://github.com/llvm/llvm-project/pull/115229 which was reverted by https://github.com/llvm/llvm-project/pull/115388 because it was hitting an assertion in IREE. The problem is that `SplatElementsAttr` might be an attr of non `APInt` (e.g. float) elements. Instead, check if `DenseIntElementsAttr` is splat.

>From a8d0cb4540ac6d7f180070558760fd1e0807026e Mon Sep 17 00:00:00 2001
From: Ian Wood <ianwood2024 at u.northwestern.edu>
Date: Fri, 8 Nov 2024 03:56:33 -0800
Subject: [PATCH] [mlir] IntegerRangeAnalysis: don't loop over splat attr

---
 mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
index 8682294c8a6972..f3413c1c30fadc 100644
--- a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
+++ b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
@@ -42,6 +42,12 @@ void arith::ConstantOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
   }
   if (auto arrayCstAttr =
           llvm::dyn_cast_or_null<DenseIntElementsAttr>(getValue())) {
+    if (arrayCstAttr.isSplat()) {
+      setResultRange(getResult(), ConstantIntRanges::constant(
+                                      arrayCstAttr.getSplatValue<APInt>()));
+      return;
+    }
+
     std::optional<ConstantIntRanges> result;
     for (const APInt &val : arrayCstAttr) {
       auto range = ConstantIntRanges::constant(val);



More information about the Mlir-commits mailing list