Skip to content

[mlir][NFC] IntegerRangeAnalysis: don't loop over splat attr #115399

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

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mlir/lib/Dialect/Arith/IR/InferIntRangeInterfaceImpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative is that you can still cast to SplatElementsAttr and then check the element type. Either way is fine.

return;
}

std::optional<ConstantIntRanges> result;
for (const APInt &val : arrayCstAttr) {
auto range = ConstantIntRanges::constant(val);
Expand Down
7 changes: 7 additions & 0 deletions mlir/test/Dialect/Vector/int-range-interface.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ func.func @constant_splat() -> vector<8xi32> {
func.return %1 : 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>
}

// 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> {
Expand Down
Loading