Skip to content

Commit 9bb9bdc

Browse files
committed
fixup! [MLIR][LLVM] Fix #llvm.constant_range crashing in storage uniquer
1 parent 9a1bb3e commit 9bb9bdc

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,8 @@ def LLVM_TBAATagArrayAttr
10941094
// ConstantRangeAttr
10951095
//===----------------------------------------------------------------------===//
10961096
def LLVM_ConstantRangeAttr : LLVM_Attr<"ConstantRange", "constant_range"> {
1097-
let parameters = (ins
1098-
"uint32_t":$width,
1099-
"::llvm::APInt":$lower,
1100-
"::llvm::APInt":$upper
1097+
let parameters = (ins APIntParameter<"">:$lower,
1098+
APIntParameter<"">:$upper
11011099
);
11021100
let summary = "A range of two integers, corresponding to LLVM's ConstantRange";
11031101
let description = [{
@@ -1111,16 +1109,13 @@ def LLVM_ConstantRangeAttr : LLVM_Attr<"ConstantRange", "constant_range"> {
11111109

11121110
Syntax:
11131111
```
1114-
`<` `i`(width) $lower `,` $upper `>`
1112+
`<` `i`(wdith($lower)), $lower `,` $upper `>`
11151113
```
11161114
}];
11171115

11181116
let builders = [
11191117
AttrBuilder<(ins "uint32_t":$bitWidth, "int64_t":$lower, "int64_t":$upper), [{
1120-
return $_get($_ctxt, bitWidth, ::llvm::APInt(bitWidth, lower), ::llvm::APInt(bitWidth, upper));
1121-
}]>,
1122-
AttrBuilder<(ins "::llvm::APInt":$lower, "::llvm::APInt":$upper), [{
1123-
return $_get($_ctxt, lower.getBitWidth(), lower, upper);
1118+
return $_get($_ctxt, ::llvm::APInt(bitWidth, lower), ::llvm::APInt(bitWidth, upper));
11241119
}]>
11251120
];
11261121

mlir/include/mlir/IR/AttrTypeBase.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ class StringRefParameter<string desc = "", string value = ""> :
383383
let defaultValue = value;
384384
}
385385

386+
// For APInts, which require comparison over different bitwidths
387+
class APIntParameter<string desc> :
388+
AttrOrTypeParameter<"::llvm::APInt", desc> {
389+
let comparator = "$_lhs.getBitWidth() == $_rhs.getBitWidth() && $_lhs == $_rhs";
390+
}
391+
386392
// For APFloats, which require comparison.
387393
class APFloatParameter<string desc> :
388394
AttrOrTypeParameter<"::llvm::APFloat", desc> {

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,13 @@ Attribute ConstantRangeAttr::parse(AsmParser &parser, Type odsType) {
278278
}
279279

280280
void ConstantRangeAttr::print(AsmPrinter &printer) const {
281-
printer << "<i" << getWidth() << ", " << getLower() << ", " << getUpper()
282-
<< ">";
281+
printer << "<i" << getLower().getBitWidth() << ", " << getLower() << ", "
282+
<< getUpper() << ">";
283283
}
284284

285285
LogicalResult
286286
ConstantRangeAttr::verify(llvm::function_ref<InFlightDiagnostic()> emitError,
287-
uint32_t width, llvm::APInt lower,
288-
llvm::APInt upper) {
289-
if (width != lower.getBitWidth())
290-
return emitError()
291-
<< "expected type and value to have matching bitwidths but got "
292-
<< width << " vs. " << lower.getBitWidth();
287+
llvm::APInt lower, llvm::APInt upper) {
293288
if (lower.getBitWidth() != upper.getBitWidth())
294289
return emitError()
295290
<< "expected lower and upper to have matching bitwidths but got "

0 commit comments

Comments
 (0)