Skip to content

Commit 09398bd

Browse files
committed
[MLIR][LLVM] Fix #llvm.constant_range parsing
1 parent c4fb718 commit 09398bd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,9 @@ Attribute ConstantRangeAttr::parse(AsmParser &parser, Type odsType) {
271271
parser.parseInteger(upper) || parser.parseGreater())
272272
return Attribute{};
273273
// For some reason, 0 is always parsed as 64-bits, fix that if needed.
274-
if (lower.isZero())
275-
lower = lower.sextOrTrunc(bitWidth);
276-
if (upper.isZero())
277-
upper = upper.sextOrTrunc(bitWidth);
274+
// Negative numbers may use more bits than `bitWidth`
275+
lower = lower.sextOrTrunc(bitWidth);
276+
upper = upper.sextOrTrunc(bitWidth);
278277
return parser.getChecked<ConstantRangeAttr>(loc, parser.getContext(), lower,
279278
upper);
280279
}

mlir/test/Dialect/LLVMIR/func.mlir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,9 @@ llvm.func @intel_reqd_sub_group_size_hint() attributes {llvm.intel_reqd_sub_grou
479479
// CHECK-SAME: llvm.workgroup_attribution = #llvm.mlir.workgroup_attribution<512 : i64, i32>
480480
// CHECK-SAME: llvm.workgroup_attribution = #llvm.mlir.workgroup_attribution<128 : i64, !llvm.struct<(i32, i64, f32)>
481481
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)>>})
482+
483+
// -----
484+
485+
// CHECK: @constant_range_negative
486+
// CHECK-SAME: llvm.range = #llvm.constant_range<i32, 0, -2147483648>
487+
llvm.func @constant_range_negative() -> (i32 {llvm.range = #llvm.constant_range<i32, 0, -2147483648>})

0 commit comments

Comments
 (0)