[Mlir-commits] [mlir] [mlir][NFC] IntegerRangeAnalysis: don't loop over splat attr (PR #115399)
Ian Wood
llvmlistbot at llvm.org
Fri Nov 8 09:45:31 PST 2024
https://github.com/IanWood1 updated https://github.com/llvm/llvm-project/pull/115399
>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 1/3] [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);
>From d2a31f2e62fe9bd46b0f41bcbc37f626d7d53d65 Mon Sep 17 00:00:00 2001
From: Ian Wood <ianwood2024 at u.northwestern.edu>
Date: Fri, 8 Nov 2024 21:33:17 -0800
Subject: [PATCH 2/3] Add dense float test
---
mlir/test/Dialect/Vector/int-range-interface.mlir | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/mlir/test/Dialect/Vector/int-range-interface.mlir b/mlir/test/Dialect/Vector/int-range-interface.mlir
index 09dfe932a52323..e958ecaad45444 100644
--- a/mlir/test/Dialect/Vector/int-range-interface.mlir
+++ b/mlir/test/Dialect/Vector/int-range-interface.mlir
@@ -17,6 +17,12 @@ func.func @constant_splat() -> vector<8xi32> {
func.return %1 : vector<8xi32>
}
+// CHECK-LABEL: func @float_constant_splat
+func.func @float_constant_splat() -> vector<8xf32> {
+ %0 = arith.constant dense<3.0> : vector<8xf32>
+ func.return %0: vector<8xf32>
+}
+
// CHECK-LABEL: func @vector_splat
// CHECK: test.reflect_bounds {smax = 5 : index, smin = 4 : index, umax = 5 : index, umin = 4 : index}
func.func @vector_splat() -> vector<4xindex> {
>From 25c894870a121bcb85f3c375d813a4e0173615c5 Mon Sep 17 00:00:00 2001
From: Ian Wood <ianwood2024 at u.northwestern.edu>
Date: Fri, 8 Nov 2024 21:44:14 -0800
Subject: [PATCH 3/3] Add comment to test
---
mlir/test/Dialect/Vector/int-range-interface.mlir | 1 +
1 file changed, 1 insertion(+)
diff --git a/mlir/test/Dialect/Vector/int-range-interface.mlir b/mlir/test/Dialect/Vector/int-range-interface.mlir
index e958ecaad45444..0263193b204015 100644
--- a/mlir/test/Dialect/Vector/int-range-interface.mlir
+++ b/mlir/test/Dialect/Vector/int-range-interface.mlir
@@ -18,6 +18,7 @@ func.func @constant_splat() -> vector<8xi32> {
}
// CHECK-LABEL: func @float_constant_splat
+// Don't crash on splat floats.
func.func @float_constant_splat() -> vector<8xf32> {
%0 = arith.constant dense<3.0> : vector<8xf32>
func.return %0: vector<8xf32>
More information about the Mlir-commits
mailing list