Skip to content

Commit

Permalink
[MLIR][LLVM] Fix #llvm.constant_range parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuree committed Jan 15, 2025
1 parent c4fb718 commit 09398bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,9 @@ Attribute ConstantRangeAttr::parse(AsmParser &parser, Type odsType) {
parser.parseInteger(upper) || parser.parseGreater())
return Attribute{};
// For some reason, 0 is always parsed as 64-bits, fix that if needed.
if (lower.isZero())
lower = lower.sextOrTrunc(bitWidth);
if (upper.isZero())
upper = upper.sextOrTrunc(bitWidth);
// Negative numbers may use more bits than `bitWidth`
lower = lower.sextOrTrunc(bitWidth);
upper = upper.sextOrTrunc(bitWidth);
return parser.getChecked<ConstantRangeAttr>(loc, parser.getContext(), lower,
upper);
}
Expand Down
6 changes: 6 additions & 0 deletions mlir/test/Dialect/LLVMIR/func.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,9 @@ llvm.func @intel_reqd_sub_group_size_hint() attributes {llvm.intel_reqd_sub_grou
// CHECK-SAME: llvm.workgroup_attribution = #llvm.mlir.workgroup_attribution<512 : i64, i32>
// CHECK-SAME: llvm.workgroup_attribution = #llvm.mlir.workgroup_attribution<128 : i64, !llvm.struct<(i32, i64, f32)>
llvm.func @workgroup_attribution(%arg0: !llvm.ptr {llvm.workgroup_attribution = #llvm.mlir.workgroup_attribution<512 : i64, i32>}, %arg1: !llvm.ptr {llvm.workgroup_attribution = #llvm.mlir.workgroup_attribution<128 : i64, !llvm.struct<(i32, i64, f32)>>})

// -----

// CHECK: @constant_range_negative
// CHECK-SAME: llvm.range = #llvm.constant_range<i32, 0, -2147483648>
llvm.func @constant_range_negative() -> (i32 {llvm.range = #llvm.constant_range<i32, 0, -2147483648>})

0 comments on commit 09398bd

Please sign in to comment.