-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] IntegerRangeAnalysis: don't loop over splat attr #115229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-mlir-arith @llvm/pr-subscribers-mlir Author: Ian Wood (IanWood1) ChangesIf the Full diff: https://github.com/llvm/llvm-project/pull/115229.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
index 8682294c8a6972..6646c189eb1c3e 100644
--- a/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
+++ b/mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
@@ -10,6 +10,7 @@
#include "mlir/Interfaces/InferIntRangeInterface.h"
#include "mlir/Interfaces/Utils/InferIntRangeCommon.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include <optional>
@@ -42,6 +43,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);
|
df085e1
to
aa13a08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some test? LGTM otherwise.
de6078a
to
ec039cd
Compare
f54cdc5 added tests to check the for the correct handling of splat values and change should really only affect the performance of very large splat constants. So, I'm not sure how this should be tested. |
Oh, yeah, I forgot we already had functional test for splats ). LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, since there's already a dense<3>
in the vector test suite
)" This reverts commit 3deee23.
Hitting assertion in IREE https://github.com/iree-org/iree/actions/runs/11732283897/job/32684201665?pr=19066 ``` iree-compile: /__w/iree/iree/third_party/llvm-project/mlir/include/mlir/IR/BuiltinAttributes.h:423: auto mlir::DenseElementsAttr::getValues() const [T = llvm::APInt]: Assertion `succeeded(range) && "element type cannot be iterated"' failed. ``` Reverts #115229
In this case we tag the PR with [NFC] (no functional change) to convey this. |
Reland #115229 which was reverted by #115388 because it was hitting an assertion in IREE. From the original change: If the `DenseIntElementsAttr` is a splat value, there is no need to loop over the entire attr. Instead, just update with the splat value. The problem with the original implementation is that `SplatElementsAttr` might be an attr of non `APInt` (e.g. float) elements. Instead, check if `DenseIntElementsAttr` is splat and use the splat value. Added a test to ensure there's no crash when handling float attrs.
If the `DenseIntElementsAttr` is a splat value, there is no need to loop over the entire attr. Instead, just update with the splat value.
…115388) Hitting assertion in IREE https://github.com/iree-org/iree/actions/runs/11732283897/job/32684201665?pr=19066 ``` iree-compile: /__w/iree/iree/third_party/llvm-project/mlir/include/mlir/IR/BuiltinAttributes.h:423: auto mlir::DenseElementsAttr::getValues() const [T = llvm::APInt]: Assertion `succeeded(range) && "element type cannot be iterated"' failed. ``` Reverts llvm#115229
…5399) Reland llvm#115229 which was reverted by llvm#115388 because it was hitting an assertion in IREE. From the original change: If the `DenseIntElementsAttr` is a splat value, there is no need to loop over the entire attr. Instead, just update with the splat value. The problem with the original implementation is that `SplatElementsAttr` might be an attr of non `APInt` (e.g. float) elements. Instead, check if `DenseIntElementsAttr` is splat and use the splat value. Added a test to ensure there's no crash when handling float attrs.
If the
DenseIntElementsAttr
is a splat value, there is no need to loop over the entire attr. Instead, just update with the splat value.