diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp index ff1636bc121b64..99d6e95c134d8d 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp @@ -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(loc, parser.getContext(), lower, upper); } diff --git a/mlir/test/Dialect/LLVMIR/func.mlir b/mlir/test/Dialect/LLVMIR/func.mlir index e2a444c1faaba1..74dd862ce8fb26 100644 --- a/mlir/test/Dialect/LLVMIR/func.mlir +++ b/mlir/test/Dialect/LLVMIR/func.mlir @@ -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 +llvm.func @constant_range_negative() -> (i32 {llvm.range = #llvm.constant_range})