Skip to content

[MLIR][LLVM] Fix #llvm.constant_range crashing in storage uniquer #135772

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 4 commits into from
Apr 16, 2025
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
4 changes: 2 additions & 2 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,8 @@ def LLVM_TBAATagArrayAttr
//===----------------------------------------------------------------------===//
def LLVM_ConstantRangeAttr : LLVM_Attr<"ConstantRange", "constant_range"> {
let parameters = (ins
"::llvm::APInt":$lower,
"::llvm::APInt":$upper
APIntParameter<"">:$lower,
APIntParameter<"">:$upper
);
let summary = "A range of two integers, corresponding to LLVM's ConstantRange";
let description = [{
Expand Down
8 changes: 8 additions & 0 deletions mlir/include/mlir/IR/AttrTypeBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ class StringRefParameter<string desc = "", string value = ""> :
let defaultValue = value;
}

// For APInts, which require comparison supporting different bitwidths. The
// default APInt comparison operator asserts when the bitwidths differ, so
// a custom implementation is necessary.
class APIntParameter<string desc> :
AttrOrTypeParameter<"::llvm::APInt", desc> {
let comparator = "$_lhs.getBitWidth() == $_rhs.getBitWidth() && $_lhs == $_rhs";
}

// For APFloats, which require comparison.
class APFloatParameter<string desc> :
AttrOrTypeParameter<"::llvm::APFloat", desc> {
Expand Down
10 changes: 10 additions & 0 deletions mlir/test/Dialect/LLVMIR/range-attr.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: mlir-opt %s -o - | FileCheck %s

// CHECK: #llvm.constant_range<i32, 0, 12>
llvm.func external @foo1(!llvm.ptr, i64) -> (i32 {llvm.range = #llvm.constant_range<i32, 0, 12>})
// CHECK: #llvm.constant_range<i8, 1, 10>
llvm.func external @foo2(!llvm.ptr, i64) -> (i8 {llvm.range = #llvm.constant_range<i8, 1, 10>})
// CHECK: #llvm.constant_range<i64, 0, 2147483648>
llvm.func external @foo3(!llvm.ptr, i64) -> (i64 {llvm.range = #llvm.constant_range<i64, 0, 2147483648>})
// CHECK: #llvm.constant_range<i32, 1, -2147483648>
llvm.func external @foo4(!llvm.ptr, i64) -> (i32 {llvm.range = #llvm.constant_range<i32, 1, -2147483648>})
Loading